2011
ASSIGNMENT # 1
Computing Fundamental
This assignment is composed of four questions done in C++ 4.5. the .cpp files are
attached with this softcopy.
Bahria University
Asadullah Baig
01-133102-021
BEE-2(A)
Question #1
#include<iostream.h>
void main()
{ //main starts
float temperature; //declaration of temperature
cout<<"Enter temperature in centigrade:"; // display
cin>>temperature;
temp=temp*(9/5)+32; //calculation of temperature
cout<<"The temperature in Farenheit is "<<temp; //display output
}
Question #2
#include<iostream.h>
void main()
int size;
cout<<"enter the size of the diamond shape";
cin>>size; //enter the size of the diamond
int space=size/2, stars=-1; // space=half of the size
for(int i=0;i<size;i++) //start of for
if(i<(size/2) ) //for the first half of the diamond
{ //if its true then space-- and stars are added by 2
space--;
stars=stars+2;
if(i>=size/2) //if its the bottom half of the diamond this will run
space++;stars=stars-2; //space will added stars decreased
for(int j=0;j<space;j++) //nested for start for spaces
cout<<" "; //nested for end
for(int w=0;w<stars;w++) //nested for start for stars
cout<<"*"; //nested for end
cout<<"\n"; //end line
} //end of for
} //end of main
Question #3
#include<iostream.h>
void main()
{double s1,s2,s3,s4,s5,t1,t2,t3,t4,t5,s,t,et,eo;
cout<<"enter the total marks in subject 1 ";
cin>>t1;
cout<<"enter the obtained marks in subject 1 ";
cin>> s1;
cout<<"enter the total marks in subject 2 ";
cin>>t2;
cout<<"enter the obtained marks in subject 2 ";
cin>> s2;
cout<<"enter the total marks in subject 3 ";
cin>>t3;
cout<< "enter the obtained marks in subject 3 ";
cin>> s3;
cout<<"enter the total marks in subject 4 ";
cin>>t4;
cout<< "enter the obtained marks in subject 4 ";
cin>> s4;
cout<<"enter the total marks in subject 5 ";
cin>>t5;
cout<< "enter the obtained marks in subject 5 ";
cin>> s5;
s=s1+s2+s3+s4+s5;
t=t1+t2+t3+t4+t5;
cout<<"enter the total marks of entry test ";
cin>>et;
cout<<"Enter the obtained marks of entry test ";
cin>>eo;
t=(s/t)*60;
t=t+((eo/et)*40);
cout<<t<<"%";
}
Question #4
#include<iostream.h>
#include<conio.h>
void main()
{ //start of main
char a; // character declaration
int h; // integer declaration will be used to store that static_cast value
int total=0; //declaration and initialization of total
while(a!='\r') //starting of while loop till user doesn’t press enter
int y=0; //declaration of y and initialization to zero
a=getch(); //getting first character from the user
h=static_cast<int>(a); //converting the character to int form
for(int i=49;i<=h;i++) //changing the value stored in h to real numerical value
y++;
total=total+y; //adding the numbers
} //end of while
cout<<total; //displaying
} //end of main