Lab 1
Lab 1
Fundamentals of Programming
1- Write the following program in your particular IDE and compile it.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout << " This is first ";
cout << " program in C++";
_getch();
return 0;
}
2- If there are compiler errors correct them and compile again. What is the output of the
program?
Answer:-
3- 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?
Answer:-
Lab 1
4- 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?
Answer:-
5- Omit the statement return 0; from the program and record the error.
Answer:
6- 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;
}
Output:-
Lab 1
7- 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"<<"\nmathematic\t"
<<90<<"\ncomputer\t"<<77<<"\nchemistry\t"<<69;
_getch();
return 0;
}
Output:-
* *
********
********
* *
* *
********
Code:-
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
cout<<"********\n*\t*\n*\t*\n*\t*\n*\t*\n*\t*\n*\t*\n********"<<endl;
cout<<"\n\n\n********\n*\t*\n*\t*\n********";
_getch();
return 0;
}
9- (Home Task) 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 <iostream>
#include <conio.h>
using namespace std;
int main ()
{
cout<<"C++"<<endl<<"programming is not "<<endl<<"that though";
_getch();
return 0;
}
Lab 1
+++++++++++++++++++++++++