C ++ Programming Lab 2016
BAHRIA UNIVERSITY
Engineering Sciences Department
Course: Computer Fundamentals Lab
Course Code: CSC-110
Term: Fall 2016
Class: BS (IT)-1A
LAB TASK
LAB Title:
C++ PROGRAMMING
Submitted By:
ANOSHA MUZAMMIL(Reg No: 02-235162-
004)
Submitted To:
SIR BILAL
(Subject Teacher)
Signature: Max Marks: Marks Obtained:
1
C ++ Programming Lab 2016
EXERCISE NO: 01
Q: Write a program that prints the following lines on the screen:
Hello World
This is MY FIRST c++ Program
#include <iostream>
Using namespace std;
int main()
{
cout<<"Hello World\n This is MY FIRST c++ Program"<<endl;
return 0;
}
2
C ++ Programming Lab 2016
EXERCISE NO: 02
Q. Write a program that prints similar to the following:
*
**
***
****
#include <iostream>
using namespace std;
int main()
{
cout<<"*"<<endl;
cout<<"**"<<endl;
cout<<"***"<<endl;
cout<<"****"<<endl;
return 0;
}
3
C ++ Programming Lab 2016
EXERCISE NO: 03
Q. Write a program that prints an elephant similar to the following:
#include <iostream>
Using namespace std;
int main()
{
cout<<" ___ ___ " <<endl;
cout<<" / \~~~/ \ " <<endl;
cout<<" --------( . . ) " <<endl;
cout<<" / \ ___ ___ / " <<endl;
cout<<" /ǀ (\ ǀ( " <<endl;
cout<<" ^\ /___\ /\ ǀ" <<endl;
cout<<" ǀ__ǀ ǀ__ǀ - ” " <<endl;
return 0;
}
4
C ++ Programming Lab 2016
EXERCISE NO: 04
Q. Write a program to take the input of 5 Integers and produce the Average of these
numbers:
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e;
int sum,avg,total;
cout<<"ENTER FIVE INTEGERE"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
sum=a+b+c+d+e;
total=5;
avg = sum/total;
total=5;
cout<<"Average of FIve Number is:"<<avg<<endl;
return 0;
}
5
C ++ Programming Lab 2016
6
C ++ Programming Lab 2016
EXERCISE NO: 05
Q. Write a program that demonstrates how to convert temperature degrees
Fahrenheit to degrees Celsius:
#include <iostream>
using namespace std;
int main()
{
float f,c;
cout<<"ENTER TEMPERATURE IN FARENHEIT"<<endl;
cin>>f;
cout<<f<<" DEGREE FARENHEIT IS EQUAL TO "<<(f-32*5/9)<<" DEGREE
CELSIUS"<<endl;
return 0;
}
7
C ++ Programming Lab 2016
EXERCISE NO: 06
Q. Type-in the following example, which receives the input of three numbers and Find the values of the
expressions for the following inputs:
a b c a-3/b+2 a-b%2+4 a+2/6+c a/b*c+1
2 5 3.8 4.00 5.00 5.80 1.00
7 6 8.3 9.00 11.00 15.30 9.30
12 8 2.9 14.00 16.00 14.90 3.90
#include <iostream>
using namespace std;
int main()
{
int a,b;
float c;
float d,e,f,g;
cout<<"ENTER THE VALUE OF A"<<endl;
cin>>a;
cout<<"ENTER THE VALUE OF B"<<endl;
cin>>b;
cout<<"ENTER THE VALUE OF C WHICH IS DECLARE IN FLOAT"<<endl;
cin>>c;
d=(a-3/b+2);
e=(a-b%2+4);
f=(a+2/6+c);
cout<<" _ _ _ ___________ ___________ ___________ ___________"<<endl;
cout<<"|A|B|C| (a-3/b+2) | (a-b%2+4) | (a+2/6+c) | (a/b*c+1) |"<<endl;
cout<<" _ _ _ ___________ ___________ ___________ ___________ "<<endl;
cout<<"|"<<a<<"|"<<b<<"|"<<c<<"| "<<d<<" | " <<e<<" | "<<f<< " | "
<<g<< " | "<<endl;
cout<<"-------------------------------------------------------"<<endl;
8
C ++ Programming Lab 2016