Beruflich Dokumente
Kultur Dokumente
QUESTIONS
1. Who is written C++ ?
Answers : Bjarne Stroustrup
b. While
Answers :
Example:
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
return 0;
}
}
cout<<"Sum = "<<sum;
return 0;
(CONTINUE)
d. While True
Example :
1 #include <iostream>
2 using namespace std;
3
4 int main (int argc, char * const argv[]) {
5
6
int counter = 9;
7
8
while (true) {
9
10
cout << "Counter: " << counter << endl;;
11
counter--;
12
13
if (counter == 0) {
14
break;
15
}
16
17
}
18
19
return 0;
20
}
21
e. Do/While
Anwers :
Example :
// do_while_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i++);
} while (i < 3);
}
f. Jump/Loop
example :
break;
continue;
return [expression];
goto identifier;
g. If/else
EXAMPLE :
#include <iostream>
using namespace std;
int main(){
int mark;
cout << "What mark did you get in the test?" << endl;
cin >> mark;
if(mark >= 90)
{
cout << "You got an A*" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 80)
{
cout << "You got an A" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 70)
{
cout << "You got an B" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 60)
{
cout << "You got an C" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 50)
{
cout << "You got an D" << endl;
cout << "You Failed!" << endl;
}
else if(mark >= 40)
{