Professional Documents
Culture Documents
Programming Fundamentals Lab Spring 2011: Lab Number: Four Registration: - FBAS/BSSE/F10 Name: Mubeen Ahmed Section: A'
Programming Fundamentals Lab Spring 2011: Lab Number: Four Registration: - FBAS/BSSE/F10 Name: Mubeen Ahmed Section: A'
Programming Fundamentals Lab Spring 2011: Lab Number: Four Registration: - FBAS/BSSE/F10 Name: Mubeen Ahmed Section: A'
Output:
2.
#include<iostream>
using namespace std;
void main()
{
int num1, num2;
cout<<"Please enter an integer:";
cin>>num1;
cout<<"\nPlease enter 2nd integer:";
cin>>num2;
cout<<"num1="<<num1<<" and num2="<<num2<<endl;
if (num1==num2)
{
cout<<"Hey,that’s a coincidence!"<<endl;
}
if (num1!=num2)
cout<<"The values are not the same.\n"<<endl;
}
Output:
3.
#include<iostream>
using namespace std;
void main()
{
int num1, num2;
cout<<"Please enter an integer:";
cin>>num1;
cout<<"\nPlease enter 2nd integer:";
cin>>num2;
cout<<"num1="<<num1<<" and num2="<<num2<<endl;
if (num1==num2)
{
cout<<"The values are the same. Hey that’s a coincidence!"<<endl;
}
if (num1!=num2)
cout<<"The values are not the same.\n"<<endl;
}
Output:
4.
#include<iostream>
using namespace std;
void main()
{
int num1, num2;
cout<<"Please enter an integer:";
cin>>num1;
cout<<"\nPlease enter 2nd integer:";
cin>>num2;
cout<<"num1="<<num1<<" and num2="<<num2<<endl;
if (num1==num2)
{
cout<<"The values are the same. Hey that’s a coincidence!"<<endl;
}
else
cout<<"The values are not the same.\n"<<endl;
system("pause");
}
Output:
Program 2)
5.
#include<iostream>
using namespace std;
void main()
{
float average;
cout<<"Input your average:";
cin>>average;
if (average>=60)
{
cout<<"\nYou Pass."<<endl;
}
if (average<60)
cout<<"\nYou Fail.\n"<<endl;
system("pause");
}
Output:
6.
#include<iostream>
using namespace std;
void main()
{
float average;
cout<<"Input your average:";
cin>>average;
if (average>=60 && average<=100)
{
cout<<"\nYou Pass."<<endl;
}
else if(average>100)
{cout<<"\nYou are so Inteligent. :)\n";
}
else
cout<<"\nYou Fail."<<endl;
system("pause");
}
Output:
7.
/*Invalid data (data above 100), ‘A’ category (90–100), ‘B’ category (80–89),
“You Pass” category (60–79), “You Fail” category (0–59).*/
#include<iostream>
using namespace std;
int main()
{
float Average;
cout<<"Enter your Average:";
cin>>Average;
if(Average>100 || Average<0)
{
cout<<"\nInvalid Data."<<endl;
}
else if(Average>=90 && Average<=100)
{
cout<<"\n'A'"<<endl;
}
else if(Average>=80 && Average<90)
{
cout<<"\n'B'"<<endl;
}
else if(Average>=60 && Average<80)
{
cout<<"\n'You Pass.'"<<endl;
}
else
cout<<"\n'You Fail.'"<<endl;
system("pause");
return 0;
}
Output:
Program 3)
#include<iostream>
using namespace std;
int main( )
{
char year;
float gpa;
cout<<"What year student are you?"<<endl;
cout<<"Enter\n1 (freshman),\n2 (sophomore),\n3 (junior),\nor\n4 (senior)"<<endl<<endl;
cin>>year;
cout<<"Now enter your GPA"<<endl;
cin>>gpa;
if (gpa>=2.0 && year=='4')
{
cout<<"It is time to graduate soon."<<endl;}
else if (gpa <2.0 || year != '4')
{
cout<<"You need more schooling."<<endl;
}
system("pause");
return 0;
}
Output:
8.
We can replace gpa>=2.0 with (!(gpa<2.0).
So, Running Program is Below:
#include<iostream>
using namespace std;
int main( )
{
char year;
float gpa;
cout<<"What year student are you?"<<endl;
cout<<"Enter\n1 (freshman),\n2 (sophomore),\n3 (junior),\nor\n4 (senior)"<<endl<<endl;
cin>>year;
cout<<"Now enter your GPA"<<endl;
cin>>gpa;
if ((!(gpa<2.0)) && year=='4')
{
cout<<"It is time to graduate soon."<<endl;}
else if (gpa <2.0 || year != '4')
{
cout<<"You need more schooling."<<endl;
}
system("pause");
return 0;
}
Output:
9.
Here we Cannot Replace Year!=’4’ with year < 4 or year <= 3
Because Year in a ‘Char’ and 4 or 3 is in ‘Int’.
____________________________________________________
_________________________
Exercise
10.
#include<iostream>
using namespace std;
int main( )
{
char Ch;
cout<<"Enter a Character: ";
cin>>Ch;
if(isalpha(Ch))
{
if(toupper(Ch)=='F')
{
cout<<"\nFrank."<<endl;
}
else if(toupper(Ch)=='C')
{
cout<<"\nChristine."<<endl;
}
else if(toupper(Ch)=='A')
{
cout<<"\nAmanda."<<endl;
}
else if(toupper(Ch)=='B')
{
cout<<"\nBernard."<<endl;
}
else
cout<<"Sorry, We Have not a 'word' from:"<<Ch<<endl;
}
else
cout<<"\nYou have not Enter a Character."<<endl;
return 0;
}
Output:
11.
#include<iostream>
using namespace std;
int main( )
{
int Quarter_1,Quarter_2,Quarter_3,Quarter_4,First,Second,Third;
float Avg_Bill=0;
cout<<"To Claculate the Avg Water Bill of 4 Quarters..."<<"\nPlz Enter:"<<endl;
cout<<"\nQuarter 1:"<<endl;
cout<<"Enter First Month Bill of Quarter_1:";
cin>>First;
cout<<"Enter Second Month Bill of Quarter_1:";
cin>>Second;
cout<<"Enter Third Month Bill of Quarter_1:";
cin>>Third;
Quarter_1=(First+Second+Third)/3;
cout<<"\nThe Avg_Bill of Quarter_1 is:$"<<Quarter_1<<endl;
cout<<"\nQuarter 2:"<<endl;
cout<<"Enter First Month Bill of Quarter_2:";
cin>>First;
cout<<"Enter Second Month Bill of Quarter_2:";
cin>>Second;
cout<<"Enter Third Month Bill of Quarter_2:";
cin>>Third;
Quarter_2=(First+Second+Third)/3;
cout<<"\nThe Avg_Bill of Quarter_2 is:$"<<Quarter_2<<endl;
cout<<"\nQuarter 3:"<<endl;
cout<<"Enter First Month Bill of Quarter_3:";
cin>>First;
cout<<"Enter Second Month Bill of Quarter_3:";
cin>>Second;
cout<<"Enter Third Month Bill of Quarter_3:";
cin>>Third;
Quarter_3=(First+Second+Third)/3;
cout<<"\nThe Avg_Bill of Quarter_3 is:$"<<Quarter_3<<endl;
cout<<"\nQuarter 4:"<<endl;
cout<<"Enter First Month Bill of Quarter_4:";
cin>>First;
cout<<"Enter Second Month Bill of Quarter_4:";
cin>>Second;
cout<<"Enter Third Month Bill of Quarter_4:";
cin>>Third;
Quarter_4=(First+Second+Third)/3;
cout<<"\nThe Avg_Bill of Quarter_4 is:$"<<Quarter_4<<endl;
Avg_Bill=(float)(Quarter_1+Quarter_2+Quarter_3+Quarter_4)/4;
cout<<"\nThe Avg Bill of Four Quarters is:$"<<Avg_Bill<<endl;
if(Avg_Bill>75)
{
cout<<"\nYou are using too much 'Water'."<<endl;
}
else if(Avg_Bill>=25 && Avg_Bill<75)
{
cout<<"\nYou are using Typical Amount of 'Water'."<<endl;
}
else
cout<<"\nThank you, for Coserving 'Water'."<<endl;
return 0;
}
Output:
Or
#include<iostream>
using namespace std;
int main( )
{
int Quarter_1,Quarter_2,Quarter_3,Quarter_4;
float Avg_Bill=0;
cout<<"To Claculate the Avg Water Bill of 4 Quarters..."<<"\nPlz Enter:"<<endl;
cout<<"\nBill of Quarter 1:";
cin>>Quarter_1;
cout<<"Bill of Quarter 2:";
cin>>Quarter_2;
cout<<"Bill of Quarter 3:";
cin>>Quarter_3;
cout<<"Bill of Quarter 4:";
cin>>Quarter_4;
Avg_Bill=(float)(Quarter_1+Quarter_2+Quarter_3+Quarter_4)/4;
cout<<"\nThe Avg Bill is:"<<Avg_Bill<<endl;
if(Avg_Bill>75)
{
cout<<"\nYou are using too much 'Water'."<<endl;
}
else if(Avg_Bill>=25 && Avg_Bill<75)
{
cout<<"\nYou are using Typical Amount of 'Water'."<<endl;
}
else
cout<<"\nThank you, for Coserving 'Water'."<<endl;
return 0;
}
Output:
12.
#include<iostream>
using namespace std;
int main( )
{
int T_Shirt,Bill;
const int Price=12;
float Discount=0,Total_Bill;
cout<<"Enter The Number of T_Shirts You Bought:";
cin>>T_Shirt;
if(T_Shirt<0)
{
cout<<"\nAlways Be +ve,Error.\a"<<endl;
}
else
{
Bill=(T_Shirt*Price);
cout<<"\nYour Bill is:"<<Bill<<endl;
13.
#include<iostream>
using namespace std;
int main( )
{
int State;
char Choice;
const double Charges_InState=3000,Charges_OutState=4500;
double Total_Fee=0;
cout<<"\tWell_Come";
cout<<"\nPress '1' to Calculate In-State Charges."<<endl;
cout<<"Press '0' to Calculate Out-of-State Charges."<<"\n"<<endl;
cin>>State;
if(State==1)
{
cout<<"Your Tution Fee is:$"<<Charges_InState<<endl;
Total_Fee=Charges_InState;
}
else if(State==0)
{
cout<<"\nYour Tution Fee is:$"<<Charges_OutState<<endl;
Total_Fee=Charges_OutState;
}
cout<<"\nDo You want Room & Board!(Y/N):";
cin>>Choice;
if(toupper(Choice)=='Y')
{
if(State==1)
{
cout<<"\nAdditional Charges is:2500";
Total_Fee=Charges_InState+2500;
}
else if(State==0)
{
cout<<"\nAdditional Charges is:3500";
Total_Fee=Charges_OutState+3500;
}
else
{
cout<<"\nYour Total Fee is:$"<<Total_Fee<<endl;
}
cout<<"\nYour Total Fee is:$"<<Total_Fee<<endl;
}
else if(toupper(Choice)=='N')
{
cout<<"\nTotal_Fee:$"<<Total_Fee<<endl;
}
return 0;
}
Output:
14.
#include<iostream>
using namespace std;
int main()
{
int N_Kms,n_kms;
double Charges;
cout<<"Well_Come,To Know The Fee of Taxi Ribe."<<endl;
cout<<"\nEnter The Number of Km's,Which you want to Travel:";
cin>>N_Kms;
if(N_Kms==1)
{
cout<<"\nThe Cost of First Kilometer is:$50"<<endl;
}
else if(N_Kms<=30)
{
n_kms=N_Kms-1;
Charges=n_kms*25;
Charges=Charges+50;
cout<<"\nYour Charges are:$"<<Charges<<endl;
}
else if(N_Kms>30)
{
n_kms=N_Kms-30;
Charges=n_kms*10;
Charges=Charges+(29*25)+50;
cout<<"\nYour Charges are:$"<<Charges<<endl;
}
return 0;
}
Output:
15.
#include<iostream>
using namespace std;
int main()
{
int N;
float F=0.00,C=0.00;
cout<<"1.Fahrenheit to Celsius"<<endl;
cout<<"2.Celsius to Fahrenheit"<<endl;
cout<<"3.To Quit"<<endl;
cout<<"\nEnter your Choice:";
cin>>N;
if(N==1)
{
cout<<"\nEnter Tempreture in Fahrenheit:";
cin>>F;
C=5*(F-32)/9;
cout<<"The Tempreture in Celsius is:"<<C<<"\n"<<endl;
}
else if(N==2)
{
cout<<"\nEnter Tempreture in Celcius:";
cin>>C;
F=(9*C/5)+32;
cout<<"The Tempreture in Fahrenhiet is:"<<F<<"\n"<<endl;
}
else if(N==3)
{
cout<<"\nThank You....."<<endl;
}
else
cout<<"\nTime is very 'Imp' in our Life."<<endl;
return 0;
}
Output:
____________________________________________________
____________________________________
The End