C++ SS22: Klausur bis Aufgabe 3
This commit is contained in:
+27
-29
@@ -174,58 +174,56 @@ std::cout << a++ << "\n";
|
|||||||
\begin{parts}
|
\begin{parts}
|
||||||
\part
|
\part
|
||||||
\begin{cppcode}
|
\begin{cppcode}
|
||||||
std::vector<double> a{1., 3., 2., 4.};
|
int *a;
|
||||||
a.at(4) = 5;
|
a = new int[6];
|
||||||
|
a[8] = 13;
|
||||||
\end{cppcode}
|
\end{cppcode}
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
Vector hat nur 4 Elemente und es würd auf Element 5 zugegriffen. (2 Pt.)
|
Array hat nur 6 Elemente und es würde auf Element 9 zugegriffen. (2 Pt.)
|
||||||
\end{solution}
|
\end{solution}
|
||||||
|
|
||||||
\part
|
\part
|
||||||
% TODO not an actuall error but only warning
|
% TODO not an actuall error but only warning
|
||||||
\begin{cppcode}
|
\begin{cppcode}
|
||||||
class SomeClass {
|
class SomeClass {
|
||||||
int a;
|
int b;
|
||||||
int& getA() const { return a;}
|
public:
|
||||||
|
SomeClass::getB(){return b}
|
||||||
};
|
};
|
||||||
\end{cppcode}
|
\end{cppcode}
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
getA kann nicht const sein und int\& zurückgeben (2 Pt.)
|
Klassenname in der Deklaration, Semikolon fehlt, Rückgabetyp fehlt (2 Pt.)
|
||||||
\end{solution}
|
\end{solution}
|
||||||
|
|
||||||
\part
|
\part
|
||||||
\begin{cppcode}
|
\begin{cppcode}
|
||||||
void scale(std::vector<double> vec, double factor) {
|
int *a;
|
||||||
for(auto& num : vec)
|
for (int i=0;i<10;i++)
|
||||||
num = num * factor;
|
a[i] = i*i;
|
||||||
}
|
|
||||||
\end{cppcode}
|
\end{cppcode}
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
Der Vektor wird als Kopie übergeben und die gehen nach Ende der Funktion verloren. (2 Pt.)
|
New vergessen
|
||||||
\end{solution}
|
|
||||||
|
|
||||||
\part
|
|
||||||
% TODO funktioniert theoretisch auch..
|
|
||||||
\begin{cppcode}
|
|
||||||
double& max(double a, double b) {
|
|
||||||
if ( a > b)
|
|
||||||
return a;
|
|
||||||
else
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
\end{cppcode}
|
|
||||||
\begin{solution}
|
|
||||||
Dangeling Ref (2 Pt.)
|
|
||||||
\end{solution}
|
\end{solution}
|
||||||
|
|
||||||
\part
|
\part
|
||||||
\begin{cppcode}
|
\begin{cppcode}
|
||||||
int len;
|
int a = 5;
|
||||||
std::cin >> len;
|
for (int i=0; i<5; i++)
|
||||||
std::array<int, len> a;
|
a += i;
|
||||||
|
std::cout <<i <<" " <<a <<std::endl;
|
||||||
\end{cppcode}
|
\end{cppcode}
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
Die Variable len ist erst zur Laufzeit bekannt. Der Array braucht aber len zur Kompilezeit (2 Pt.)
|
i ist in einem anderen Scope (2 Pt.)
|
||||||
|
\end{solution}
|
||||||
|
|
||||||
|
\part
|
||||||
|
\begin{cppcode}
|
||||||
|
int a = 5;
|
||||||
|
for (int i=0; i<5; i++)
|
||||||
|
i -= a;
|
||||||
|
\end{cppcode}
|
||||||
|
\begin{solution}
|
||||||
|
Schleife erreicht nie das Ende (2 Pt.)
|
||||||
\end{solution}
|
\end{solution}
|
||||||
\end{parts}
|
\end{parts}
|
||||||
\end{aufgabe}
|
\end{aufgabe}
|
||||||
|
|||||||
Reference in New Issue
Block a user