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

Lab 1

This document summarizes the steps taken in Lab 1 of a fundamentals of programming course. It describes writing a simple "Hello World" style program in C++, compiling it, and correcting errors. It then has the student make small alterations to introduce and fix errors, and write additional programs to output shapes and a table with text formatting.

Uploaded by

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

Lab 1

This document summarizes the steps taken in Lab 1 of a fundamentals of programming course. It describes writing a simple "Hello World" style program in C++, compiling it, and correcting errors. It then has the student make small alterations to introduce and fix errors, and write additional programs to output shapes and a table with text formatting.

Uploaded by

Zain Ul Abdeen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab 1

Fundamentals of Programming

Lab Journal – Lab 1


Writing the first program

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:-

1>------ Build started: Project: Project1, Configuration: Debug Win32 ------


1> first proj.cpp
1> Project1.vcxproj -> c:\users\dell\documents\visual studio
2012\Projects\Project1\Debug\Project1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

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:

There is no error in the program.

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:-

8- Now Write a program yourself to print a rectangle and a Square on screen.


********
* *
* *
* *
* *
* *
Lab 1

* *
********

********
* *
* *
********
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:

cout << “This is a test message “ << endl;


cout << “This is a” << endl << “test message “ << endl;

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

+++++++++++++++++++++++++

You might also like