Professional Documents
Culture Documents
Lab Journal 1
er:
Task # 1.1:
• Write the following program in your particular IDE and compile it.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
_getch();
return 0;
}
If there are compiler errors correct them and compile again. What is the output of the
program?
In case you didn't have any typing errors on your first attempt, we'll introduce some now.
Change the word cout in the source program to couts and try to compile the program. How
does your compiler inform you of this error?
Correct the error introduced in the above step, and then remove the semicolon from the end
of the first line. Try to compile this altered version. How does your compiler respond?
Omit the statement return 0; from the program and record the error.
Result/Output:
Analysis/Conclusion:
We learn the basic structure of c++ and learn to debug the error
Task # 1.2:
Write this code in your compiler, see its output and write it below.
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
cout << “#\n$$\n@@@\n****\n#####\n”;
_getch();
return 0;
}
Result/Output:
Analysis/Conclusion:
We use \n. the function of \n. is move the cursor to next line
Task # 1.3:
Write this code in your compiler, see its output and write it below.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<<"subject " <<"\tmarks"<<"\nenglish\t"
<<90<<"\nmaths\t"<<77<<"\nphysics\t"<<69;
_getch();
return 0;
}
Result/Output:
Analysis/Conclusion:
Manipulators are operators that are used with insertion operator (<<) to control format of data.
A very useful manipulator is ‘endl’ which stands for ‘end of line’.
It inserts a new line and is used as follows:
Write the program using endl manipulator to display the following text:
C++
programming is not
that though
Code:
#include <
#include <conio.h>
using namespace std;
int main()iostream>
{
cout << "C++" << endl;
cout << "programming is not" << endl << "that tough" << endl;
_getch();
return 0;
n
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout << "this is the text messege" << endl;
cout << "this is a" << endl << "text messege" << endl;
_getch();
retur0;
}
Result/Output:
Analysis/Conclusion:
Task # 1.5:
Write a program that prints any two shapes as follows :
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout << "*********\n" << "*\t" << "*\n";
cout << "*\t" << "*\n" <<"*\t" <<"*\n" <<"*\t" <<"*\n";
cout << "*\t" <<"*\n" <<"*\t" <<"*\n" <<"*\t" <<"*\n" << "*********";
_getch();
return 0;
}
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout << " *\n" << " ***\n" << " *****\n";
cout << " *\n" << " *\n" << " *\n";
cout << " *\n" << " *\n" << " *\n";
_getch();
return 0;
}
Result/Output:
Analysis/Conclusion:
Write a program that asks the user to enter two numbers, obtains the two numbers from
the user and prints the sum, product, difference, average and quotient of the two
numbers. The screen dialogue should appear as follows :
Enter two different positive integers (First one should be greater than the second):
23 12
Sum is 35
Product is 276
Difference is 11
Average is 7
Quotient is 11