C++ lab exercise for first year student cin>>course;
cout << "I like " <<course << "
1. #include<iostream>
too!\n \n\t THANK YOU";
using namespac std;
return 0;
int main()
{ }
Int age,year;
String name,depe; 3. // assignment operator
char grade; // in this program we are only assigning
age = 20, year = 2018; the value of b to a at the moment of the
name = "Ahmed",depe = "software"; assignment operation. Therefore a later
grade = 'A'; change of b will not affect the new value
cout<<"\t\tPersonal profile \n\n"; of a.
cout<<"\tName of the student is #include<iostream>
"<<name<<'\n'; using namespace std;
cout<<"\tDepartment of a student
int main ()
"<<depe<<'\n';
{
cout<<"\tYear of student "<<year<<'\n';
cout<<"\tAge of student "<<age<<'\n'; int a, b; // a:?, b:?
cout<<"\tGrade of student a = 10; // a:10, b:?
"<<grade<<'\n'; b = 4; // a:10, b:4
return 0; a = b; // a:4, b:4
} b = 7; // a:4, b:7
cout << "a:";
2. #include <iostream> cout << a;
using namespace std; cout << " b:";
int main () cout << b;
{ return O;
string name, course; }
int age, your_id;
cout << "What's your name?"; 4. #include<iostream>
cin>>name; using namaspace std;
cout << "Hello " << name << int main()
".\n\t"; {
Intvar1,var2,swap;
cout << "Can you tell me your age
cout<<"Enter two numbers you want to
please?";
swap \n";
cin>>age;
cin>>var1>>var2;
cout << "please write your ID?"; cout<<"Values before
cin>>your_id; swapping:"<<endl;
cout <<name<<" your Id is cout<<"First intger = "<<var1<<endl;
"<<your_id<<"\n\t"; cout<<"Second intger = "<<var2<<endl;
cout << "what is your favorite swap = var1;
course?"; var1 = var2;
1|Page
var2 = swap; int i;
cout<<"Values after swapping:"<<endl; cout<< "Please enter an integer value: ";
cout<<"First intger = "<<var1<<endl; cin>> I;
cout<<"Second intger = "<<var2<<endl; cout<< "The value you entered is " << i;
return 0; cout<< " and its double is " << i*2 << ".\n";
}
return O;
}
5. #include<iostream>
using namespace std;
int main() 8. #include<iosteam>
{ using namespace std;
Int workDays; int main()
float workHours,payRate,weeklyPay; {
workDays = 5; string fname,mname;
workHours = 7.5; cout<<"Enter u'rfname:"<<endl;
payRate = 38.5; cin>Ffname;
weeklyPay = workDays * workHours * cout<<"Enter u'rmname:"<<endl;
payRate;
cin>>Mname;
cout<<"Weekly Pay = ";
cout<<"Your full is name :"<<Fname<<"
cout<<weeklyPay;
"<<Mname;
return 0;
return 0;
}
}
6. #include<iostream>
9. // operating with variables
using namespace std;
#include <iostream>
int main ()
using namespace std;
{
int main ()
int a=5; // initial value: 5
{
int b(3); // initial value: 3
int a, b; // declaring variables:
int c(2); // initial value: 2
int result;
int result; // initial value undetermined
a = 5;
a = a + b;
b = 2; // process:
result = a - c;
a = a + 1;
cout<< result;
result = a-b;
return 0;
cout << “result”; // print out the result:
}
return 0; // terminate the program:
}
7. #include <iostream>
using namespace std;
int main ()
{
2|Page