int x = 5; int y = 7, z = 9; cout << x << ' ' << y ' ' << z << endl; x = y; y = z; z = x; cout << x << ' ' << y ' ' << z << endl; x = y; y = z; z = x; cout << x << ' ' << y ' ' << z << endl;
int x = 5, y = 2, z = 3; cout << x * y + z << endl; cout << x * y / y / x << endl; cout << x / z << ' ' << x % z << endl; cout << y / z << ' ' << y % z << endl; cout << x - y * z - x << endl;
int x = 5, y = 2, z = 3; cin >> x >> y >> z; // NO endl cout << x << ' ' << y << ' ' << z << endl;
(0, 0) to (200, 200) or to (400, 400) verbs: Frame, Paint, Erase, Invert objects: Rect, Oval, Circle Also: MoveTo, LineTo, DrawLine, ShowText SetForeColor(red, green, blue);
for (int N = 1; N <= 15; N += 3) cout << N <<" "<< N / 2 << endl;
Write a loop with this output:
1 2 4 8 16 32 64
int x = 1;
int y = 1;
while (x < 200){
cout << x << " " << y << endl;
x = 2*x;
y = y + x;
}
x = 100;
do {
cout << x << endl;
x /= 3;
} while (x > 1)
int x = 100; if (x % 9 == 1) cout << "OK" << endl; if (x % 9 == 3) x = x - 11; else x = x + 4; cout << x << endl; cout << "enter x: "; cin >> x; // try 100, 72, 35 if (x % 5 == 0) if (x % 10 == 0) cout << "divisible by 10" << endl; else cout << "not divisible by 5" << endl;
and && or || not ! equals == < <= > >= != (3 < 5) or (7 < 2) (3 < 5) and (7 < 2)
Write a C++ logical expression for each of the following:
// function prototype
void somestuff();
void otherstuff();
main()
{
somestuff();
cout << "Now is the time" << endl;
otherstuff();
cout << "For all good dogs" << endl;
otherstuff();
somestuff();
cout << "To find their bones." << endl;
}
void somestuff()
{
cout << "+=+=+=+" << endl;
}
void otherstuff()
{
for (int K = 0; K < 6; K++)
cout << K << ' ' << " *** ";
cout << endl;
}
int x = 2; y = 9;
while (x < y)
x = F(x, y);
xout << x << ' ' << y << endl;
int F(int x, int y){
if (x < y)
return 2*x;
else
return 2*y;;
}
These are the functions from the Little Function Lab. You should be able to write them.
int A[8] = { 3, 5, 4, 2, -1, 7, 0, 6 };
void WriteArray(int A[], int N){
for (int J = 0; J < N; J++)
cout << J << ' ' << A[J] << endl;
cout <<, endl;
}
for (int J = 0; J < 8; J++)
if (A[J] < 1) A[J] = 1;
WriteArray(A, 8);
for (int J = 0; J < 7; J++)
A[J] += A[J+1];
WriteArray(A, 8);
for (int J = 0; J < 8; J++)
A[J] = A[(J*J) % 8];
WriteArray(A, 8);