Programming Fundamental Lab 1
Programming Fundamental Lab 1
TASK #1:
What is header file, and why we use header files in programs?
SOLUTION:
The type file usually included by #include is called a header file. Header Files of C++
Header files contain definitions of Functions and Variables, which is imported or used
into any C++ program by using the pre-processor #include statement. Header file have
an extension ".h" which contains C++ function declaration and macro definition. iostream.h
When we want to use any function in our C++ program then first, we need to import Example
their definition from C++ library, for importing their declaration and definition we need
to include header file in program by using #include.
1. Standard library header files: These are the pre-existing header files already available in the
C/C++ compiler.
2. User-defined header files: Header files starting #define can be designed by the user.
Task #2:
What is difference between data type and return type?
SOLUTION:
DATA-TYPE:
All variables use data-type during
declaration to restrict the type of data to be
stored. Therefore, we can say that data
types are used to tell the variables the type
of data it can store. Example
General syntax of declaration of data type is
• data_type variable_name;
• Example: int a;
RETURN-TYPE:
In C++, function return type is a value returned before a function completes its execution and exits.
TASK #3:
Is it possible the execution of program without main function? What is the importance of
this function?
SOLUTION:
No, it is not possible the execution of program without main function.
main() function is the entry point of any C++ program. It is the point at which execution of program is
started. When a C++ program is executed, the execution control goes directly to the main() function.
Every C++ program have a main() function.
Page 2 of 3
TASK #4:
Create the source file, write the following program, and observe the output.
#include <iostream.h>
#include <conio.h>
void main ( )
{
clrscr( );
cout <<"Welcome to University of Engineering And Technology Taxila";
}
SOLUTION:
I am using the a little bit advance compiler than Turbo C++, therefore in Dev-C++
compiler “.h”, “void” with main function and “clrscr()” not work. So, I am using some
alternate expression, which depends compiler to compiler.
TASK #5:
Write a program and define three variables to show the following output.
The Grande Hotel has 15 floors
with 300 rooms and 30 suites
SOLUTION:
Zoom and Copy Source Code
#include <iostream>
using namespace std;
int main ( )
{
int floors, rooms, suites;
floors = 15;
rooms = 300;
suites = 30;
cout << "The Grande Hotel has " << floors << " floors\n";
cout << "with " << rooms << " rooms and " << suites;
cout << " suites\n";
return 0;
}
Page 3 of 3
TASK #6:
Write program that display your information using cout statement. The information contains your name,
father name, registration no, section.
SOLUTION:
SOURCE CODE
#include <iostream>
using namespace std;
int main ( )
{
cout<<"Student Name:- KHAWAR KHALIL\n"
<<"Father Name:- KHALIL AHMED\n"
<<"Registration No:- 19-EE-147\n"
<<"Section:- C";
return 0;
}