0% found this document useful (0 votes)
4 views

Lab 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 1

1. Create a folder named C++ Programming (store it wherever you want)

2. Create a folder named Program_Structure in side C++ Programming

3. In Program_Structure folder create a file name 1.c with the following code:

#include <iostream>
int main()
{
std::cout << "Hello World!";
}

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

// operating with variables


#include <iostream>
using namespace std;

int main ()
{
// declaring variables:
int a, b;
int result;

// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
cout << result;

// terminate the program:


return 0;
}

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

#include <iostream>
using namespace std;
int main ()

Lab 1 1
{
int a=5; // initial value: 5
int b(3); // initial value: 3
int c{2}; // initial value: 2
int result; // initial value undetermined
a = a + b;
result = a - c;
cout << result;
return 0;
}

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

#include <iostream>
using namespace std;
int main ()
{
char gender;
cin >> gender;
cout << "The gender is "<<gender;
return 0;
}

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

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

int main ()
{
string name;
cout << "What is your name?";
getline(cin,name);

cout << "My name is " << name;

return 0;
}

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

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

Lab 1 2
int main ()
{
int year = 365;
string name;
int age;
int result;

cout << "Please input your name: ";


getline(cin,name);

cout << "Please input your age: ";


cin >> age;
result = age * year;

cout << name <<" has been born "<<result<<" days";


return 0;
}

9. Please zip the file then upload it.

Lab 1 3

You might also like