0% found this document useful (0 votes)
8 views5 pages

Lab 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Lab 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab 2

1. Create a folder named statements in side C++ Programming

2. In statements folder create a file name 1.c with the following code:

#include<iostream>
using namespace std;

int main()
{
int x;
cin >> x;
if (x == 100)
cout << "x is 100";
}

3. Create a file name 2.c with the following code:

#include<iostream>
using namespace std;

int main()
{
int x;
cin >> x;
if (x == 100){
cout << "x is ";
cout << x;
}
}

4. Create a file name 3.c with the following code:

#include<iostream>
using namespace std;

int main()
{
int x;
cin >> x;
if (x == 100)
cout << "x is 100";

Lab 2 1
else
cout << "x is not 100";
}

5. Create a file name 4.c with the following code:

#include<iostream>
using namespace std;

int main()
{
int x;
cin >> x;
if (x > 0)
cout << "x is positive";
else if (x < 0)
cout << "x is negative";
else
cout << "x is 0";
}

6. Create a file name 5.c with the following code:

#include<iostream>
using namespace std;

int main()
{
int n = 10;

while (n>0) {
cout << n << ", ";
--n;
}
cout << "liftoff!\n";
}

7. Create a file name 6.c with the following code:

#include <iostream>
#include <string>
using namespace std;

int main()
{

Lab 2 2
string str;
do{
cout << "Enter text: ";
getline (cin, str);
cout << "You entered: " << str << '\n';
}while (str != "goodbye");
}

8. Create a file name 7.c with the following code:

#include <iostream>
using namespace std;

int main(){
for (int n=10; n>0; n--){
cout << n << ", ";
}
cout << "liftoff!\n";
}

9. Create a file name 8.c with the following code:

#include <iostream>
#include <string>
using namespace std;

int main ()
{
string str = "Hello!";
for (char c : str)
{
cout << "[" << c << "]";
}
cout << '\n';
}

10. Create a file name 9.c with the following code:

#include <iostream>
using namespace std;

int main ()
{
for (int n=10; n>0; n--)
{

Lab 2 3
cout << n << ", ";
if (n==3)
{
cout << "countdown aborted!";
break;
}
}
}

11. Create a file name 10.c with the following code:

#include <iostream>
using namespace std;

int main ()
{
for (int n=10; n>0; n--) {
if (n==5) continue;
cout << n << ", ";
}
cout << "liftoff!\n";
}

12. Create a file name 11.c with the following code:

#include <iostream>
using namespace std;

int main ()
{
int n=10;
mylabel:
cout << n << ", ";
n--;
if (n>0) goto mylabel;
cout << "liftoff!\n";
}

13. Create a file name 12.c with the following code:

#include <iostream>
using namespace std;

int main ()
{

Lab 2 4
int x;
cout << "Input x value: ";
cin >> x;
switch (x) {
case 1:
case 2:
case 3:
cout << "x is 1, 2 or 3";
break;
default:
cout << "x is not 1, 2 nor 3";
}
}

14. Zip the file then upload it.

Lab 2 5

You might also like