Name Roll # Class Department Submitted to
Bilal
Maqbool
10 BS-SE I CS & IT Sir.Aftab
Naseem.
C++ Programs of if-else Structure
#include <iostream.h> 1
#include <conio.h>
void main()
{
int Units,Price;
int line_rent=150;
float Total;
cout<<"Enter Units Consumed=";
cin>>Units;
if((Units>=0) && (Units<=100))
{
Price=Units*5;
}
else if(Units>100 && Units<=200)
{
Price=Units*10;
}
else if((Units>200 && Units<=500))
{
Price=Units*15;
}
else if(Units>500)
{
Price=(Units*20)+1000;
}
else
{
cout<<"Invalid Unit Entered";
}
Total=Price+line_rent;
cout<<"Total Bill for the "<< Units <<" Units Consumed is Rs."<<Total;
getch();
#include <iostream.h> 2
#include <conio.h>
void main()
{
int Sales,Bonus,Fine,Comm;
Bonus=1000;
Fine=100;
cout<<"Sales=";
cin>>Sales;
if((Sales<=10000) && (Sales>=0))
{
if(Sales<=2000)
{
Comm=(5/100*Sales)-Fine;
}
else
{
Comm=(Sales*5/100);
}
}
else if(Sales>10000 && Sales<=20000)
{
Comm=(Sales*10/100);
}
else if(Sales>20000)
{
Comm=(Sales*15/100);
Comm+=Bonus;
}
else
{ cout<<"Ivalid NO."; }
cout<<"Commission on "<<Sales<<" is="<<Comm;
getch();
}
#include <iostream.h> 3
#include <conio.h>
void main()
{
int n;
cout<<"Enter an integer value=";
cin>>n;
if(n%5==0 && n%2==0)
{
cout<<"Number is divisible by 5 & 2"<<endl;
}
else
{
cout<<"Number is not divisible by 5 & 2"<<endl;
}
getch();
}
#include <iostream.h> 4
#include <conio.h>
void main()
{
float a,b,c,max;
cout<<"Enter first value=";
cin>>a;
cout<<"Enter second value=";
cin>>b;
cout<<"Enter third value=";
cin>>c;
max=a;
if(max<b)max=b;
if(max<c)max=c;
cout<<"Maximum value is="<<max;
getch();
}
#include <iostream.h> 5
#include <conio.h>
void main()
{
int n;
clrscr();
cout<<"Enter integer value=";
cin>>n;
if(n%2==0)
{ cout<<"Even No."; }
else
{ cout<<"Odd No."; }
getch();
}
#include <iostream.h> 6
#include <conio.h>
void main()
{
int Year;
clrscr();
cout<<"Enter value for Year=";
cin>>Year;
if(Year%4==0)
{
cout<<"Leap Year";
}
else
{
cout<<"Not Leap Year";
}
getch();
}
#include <iostream.h> 7
#include <conio.h>
void main()
{
int avg;
cout<<"Enter Average Marks=";
cin>>avg;
if(avg>=90)
{ cout<<"A+"; }
else if(avg>=80)
{ cout<<"Your Grade is A"; }
else if(avg>=70)
{ cout<<"Your Grade is B"; }
else if(avg>=55)
{ cout<<"Your Grade is C"; }
else if(avg>=45)
{ cout<<"Your Grade is D"; }
else if(avg>=33)
{ cout<<"Your Grade is E"; }
else
{ cout<<"Sorry! Your are FAIL"; }
getch();
}
#include <iostream.h> 8
#include <conio.h>
void main()
{
int n;
clrscr();
cout<<"Enter integer value=";
cin>>n;
if(n%2==0)
{ cout<<"Any body LOVES you";
}
else
{ cout<<"Any body HATES you";
}
getch();
}
#include <iostream.h> 9
#include <conio.h>
void main()
{
int A,B;
cout<<"Enter your height Person A in feet=";
cin>>A;
cout<<"Enter your height Person B in feet=";
cin>>B;
if(A>B)
{ cout<<"Person A is taller than Person B"; }
else if(A<B)
{ cout<<"Person B is taller than Person A"; }
else
{ cout<<"Person A & Person B, are of equal height"; }
getch();
}
#include <iostream.h> 10
#include <conio.h>
void main()
{
int marks;
cout<<"Enter your Marks in %age =";
cin>>marks;
if(marks>=85 && marks<=100)
{ cout<<"You will get admission on Merit and Scholarship."; }
else if(marks<85 && marks>=60)
{ cout<<"You will get admission on Merit."; }
else if(marks>100)
{ cout<<"Sorry! You entered wrong %age."; }
else if(marks<60 && marks>=45)
{ cout<<"You will get admission on Self-Support."; }
else if(marks<45 && marks>0)
{ cout<<"Sorry! You are not eligible."; }
else
{ cout<<"Sorry! You entered wrong %age."; }
getch();
}
C++ Programs of switch Structure
C++ Programs of loop Structure
#include <iostream.h> 1
#include <conio.h>
void main()
{
int n;
cout<<"Enter No. of weekdays as
1=Mon,2=Tues,3=Wed,4=Thus,5=Fri,6=Sat,7=Sun";
cin>>n;
switch(n)
{
case 1:
{ cout<<"Monday";
break; }
case 2:
{ cout<<"Tuesday";
break; }
case 3:
{ cout<<"Wednesday";
break; }
case 4:
{ cout<<"Thusday";
break; }
case 5:
{ cout<<"Friday";
break; }
case 6:
{ cout<<"Saturday";
break; }
case 7:
{ cout<<"Sunday";
break; }
default:
{ cout<<"Invalid No. entered"; }
}
getch();
}
#include <iostream.h> 2
#include <conio.h>
void main()
{
char ch;
cout<<"Enter a single character=";
cin>>ch;
switch(ch)
{
case'a':
case'A':
case'e':
case'E':
case'i':
case'I':
case'o':
case'O':
case'u':
case'U':
{ cout<<"It is a vowel";
break;
}
default:
{ cout<<"It is constant"; }
}
getch();
}
#include <iostream.h> 3
#include <conio.h>
void main()
{
int marks;
cout<<"Enter your marks in %age as 1 for more than 60%,
2 for less than 60%";
cin>>marks;
switch(marks)
{
case 1:
{
cout<<"You are Eligible for admission.";
break;
}
default:
{
cout<<"You are not Eligible for admission.";
}
}
getch();
}
#include <iostream.h> 4
#include <conio.h>
void main()
{
int game;
cout<<"Enter a number(1-9) to see your Future";
cin>>game;
switch(game)
{ case 1:
{ cout<<"You wiil remain Happy";
break; }
case 2:
{ cout<<"You wiil remain Sad";
break; }
case 3:
{ cout<<"You wiil remain Enjoful";
break; }
case 4:
{ cout<<"You wiil remain Lazy";
break; }
case 5:
{ cout<<"You wiil remain Charming";
break; }
case 6:
{ cout<<"You wiil remain ILL";
break; }
case 7:
{ cout<<"You wiil remain Angry";
break; }
case 8:
{ cout<<"You wiil remain Alone";
break; }
default:
{ cout<<"You wiil remain Healthy"; }
}
getch();
}
#include <iostream.h> 5
#include <conio.h>
void main()
{
int stars;
cout<<"Enter 5 to print five,10 for 10 & 15 for 15 stars=";
cin>>stars;
switch(stars)
{
case 5:
{ cout<<"*****";
break; }
case 10:
{ cout<<"**********";
break; }
default:
{ cout<<"***************"; }
}
getch();
}
#include <iostream.h> 1
#include <conio.h>
void main()
{
int sum=0;
for(int a=1;a<=5;a++)
{
sum+=a;
}
cout<<"Sum="<<sum;
getch();
}
#include <iostream.h> 2
#include <conio.h>
void main()
{
int num;
num=1;
while(num<=15)
{
cout<<'n'<<" Hello World ";
num++;
}
getch();
}#include <iostream.h> 3
#include <conio.h>
void main()
{
int square,cube,n;
n=2;
cout<<"No.tSquaretCuben";
while(n<=7)
{
cout<<n<<'t'<<n*n<<'t'<<n*n*n<<'t'<<endl;
n++;
}
getch();
}
#include <iostream.h> 4
#include <conio.h>
void main()
{ long n;
n=3;
while(n<=715)
{ cout<<n<<'t';
n*=5;
n++;
}
getch();
}
#include <iostream.h> 5
#include <conio.h>
void main()
{
long c,t,n;
cout<<"Enter a no. for table=";
cin>>n;
t=1;
while(t<=10)
{
c=n*t;
cout<<n<<"*"<<t<<"="<<c<<'n';
t++;
}
getch();
}
#include <iostream.h> 6
#include <conio.h>
void main()
{
long r,n;
cout<<"Enter any no.=";
cin>>n;
while(n>0)
{
r=n%10;
cout<<r;
n=n/10;
}
getch();
}
#include <iostream.h> 7
#include <conio.h>
void main()
{
float marks;
char st_name[25],st_address[15],opt;
do
{
cout<<"Enter name of student=";
cin>>st_name;
cout<<"Enter address of student=";
cin>>st_address;
cout<<"Enter obtained marks=";
cin>>marks;
cout<<"Student record is="<<endl;
cout<<st_name<<'t'<<st_address<<'t'<<marks<<endl;
cout<<"More Record [Y/N]?";
cin>>opt;
}
while(opt=='y'||opt=='Y');
{ cout<<"OK"; }
getch();
}
8
#include <iostream.h>
#include <conio.h>
void main()
{
int n,tab;
cin>>tab;
n=1;
do
{
cout<<n<<"X"<<tab<<"="<<tab*n<<endl;
n++;
}
while(n<=10);
getch();
}
#include <iostream.h> 9 #include <iostream.h> 10
C++ Programs of Nested loop Structure
#include <iostream.h> 1
#include <conio.h>
void main()
{
unsigned long n,p;
for(n=1,p=1;n<=10;n++)
{ if(n%2==1)
{
p=p*n;
cout<<n<<endl;
}
}
cout<<"Product of odd no's="<<p;
getch();
}
#include <iostream.h> 2
#include <conio.h>
void main()
{
int n;
for(n=2;n<=50;n++)
{
if(n%2==0)
{ cout<<n<<'t'; }
}
getch();
}
#include <iostream.h> 3
#include <conio.h>
void main()
{
int a=10;
char y;
do
{
for(int i=1;i<=10;i++)
{
cout<<a<<"*"<<i<<"="<<a*i<<endl;
}
cout<<"for repeat Y";
cin>>y;
}
while(y=='y' || y=='Y');
getch();
}
#include <iostream.h> 4
#include <conio.h>
void main()
{
int a=10;
char y;
do
{
for(int i=1;i<=10;i++)
{
cout<<"*"<<endl;;
}
cout<<"for repeat Y ";
cin>>y;
}
while(y=='y' || y=='Y');
getch();
}
#include <iostream.h> 5
#include <conio.h>
void main()
{
int a=11;
char y;
do
{
for(int i=1;i<=11;i++)
{
cout<<"This is nested loop"<<endl;;
}
cout<<"for repeat Y ";
cin>>y;
}
while(y=='y' || y=='Y');
getch();
}
#include <iostream.h> 6
#include <conio.h>
void main()
{ int a=2;
char y;
do
{ do
{ for(int i=1;i<=10;i++)
{ cout<<a<<"X"<<i<<"="<<a*i<<endl;;
}
cout<<"for repeat Y ";
cin>>y;
}
while(y=='y' || y=='Y');
cout<<"for again repeat y ";
cin>>y;
}
while(y=='Y' || y=='Y');
getch();
}

Programming assignment 02 (bilal maqbool 10) 2011

  • 1.
    Name Roll #Class Department Submitted to Bilal Maqbool 10 BS-SE I CS & IT Sir.Aftab Naseem.
  • 2.
    C++ Programs ofif-else Structure #include <iostream.h> 1 #include <conio.h> void main() { int Units,Price; int line_rent=150; float Total; cout<<"Enter Units Consumed="; cin>>Units; if((Units>=0) && (Units<=100)) { Price=Units*5; } else if(Units>100 && Units<=200) { Price=Units*10; } else if((Units>200 && Units<=500)) { Price=Units*15; } else if(Units>500) { Price=(Units*20)+1000; } else { cout<<"Invalid Unit Entered"; } Total=Price+line_rent; cout<<"Total Bill for the "<< Units <<" Units Consumed is Rs."<<Total; getch(); #include <iostream.h> 2 #include <conio.h> void main() { int Sales,Bonus,Fine,Comm; Bonus=1000; Fine=100; cout<<"Sales="; cin>>Sales; if((Sales<=10000) && (Sales>=0)) { if(Sales<=2000) { Comm=(5/100*Sales)-Fine; } else { Comm=(Sales*5/100); } } else if(Sales>10000 && Sales<=20000) { Comm=(Sales*10/100); } else if(Sales>20000) { Comm=(Sales*15/100); Comm+=Bonus; } else { cout<<"Ivalid NO."; } cout<<"Commission on "<<Sales<<" is="<<Comm; getch(); } #include <iostream.h> 3 #include <conio.h> void main() { int n; cout<<"Enter an integer value="; cin>>n; if(n%5==0 && n%2==0) { cout<<"Number is divisible by 5 & 2"<<endl; } else { cout<<"Number is not divisible by 5 & 2"<<endl; } getch(); } #include <iostream.h> 4 #include <conio.h> void main() { float a,b,c,max; cout<<"Enter first value="; cin>>a; cout<<"Enter second value="; cin>>b; cout<<"Enter third value="; cin>>c; max=a; if(max<b)max=b; if(max<c)max=c; cout<<"Maximum value is="<<max; getch(); } #include <iostream.h> 5 #include <conio.h> void main() { int n; clrscr(); cout<<"Enter integer value="; cin>>n; if(n%2==0) { cout<<"Even No."; } else { cout<<"Odd No."; } getch(); } #include <iostream.h> 6 #include <conio.h> void main() { int Year; clrscr(); cout<<"Enter value for Year="; cin>>Year; if(Year%4==0) { cout<<"Leap Year"; } else { cout<<"Not Leap Year"; } getch(); } #include <iostream.h> 7 #include <conio.h> void main() { int avg; cout<<"Enter Average Marks="; cin>>avg; if(avg>=90) { cout<<"A+"; } else if(avg>=80) { cout<<"Your Grade is A"; } else if(avg>=70) { cout<<"Your Grade is B"; } else if(avg>=55) { cout<<"Your Grade is C"; } else if(avg>=45) { cout<<"Your Grade is D"; } else if(avg>=33) { cout<<"Your Grade is E"; } else { cout<<"Sorry! Your are FAIL"; } getch(); } #include <iostream.h> 8 #include <conio.h> void main() { int n; clrscr(); cout<<"Enter integer value="; cin>>n; if(n%2==0) { cout<<"Any body LOVES you"; } else { cout<<"Any body HATES you"; } getch(); } #include <iostream.h> 9 #include <conio.h> void main() { int A,B; cout<<"Enter your height Person A in feet="; cin>>A; cout<<"Enter your height Person B in feet="; cin>>B; if(A>B) { cout<<"Person A is taller than Person B"; } else if(A<B) { cout<<"Person B is taller than Person A"; } else { cout<<"Person A & Person B, are of equal height"; } getch(); }
  • 3.
    #include <iostream.h> 10 #include<conio.h> void main() { int marks; cout<<"Enter your Marks in %age ="; cin>>marks; if(marks>=85 && marks<=100) { cout<<"You will get admission on Merit and Scholarship."; } else if(marks<85 && marks>=60) { cout<<"You will get admission on Merit."; } else if(marks>100) { cout<<"Sorry! You entered wrong %age."; } else if(marks<60 && marks>=45) { cout<<"You will get admission on Self-Support."; } else if(marks<45 && marks>0) { cout<<"Sorry! You are not eligible."; } else { cout<<"Sorry! You entered wrong %age."; } getch(); }
  • 4.
    C++ Programs ofswitch Structure C++ Programs of loop Structure #include <iostream.h> 1 #include <conio.h> void main() { int n; cout<<"Enter No. of weekdays as 1=Mon,2=Tues,3=Wed,4=Thus,5=Fri,6=Sat,7=Sun"; cin>>n; switch(n) { case 1: { cout<<"Monday"; break; } case 2: { cout<<"Tuesday"; break; } case 3: { cout<<"Wednesday"; break; } case 4: { cout<<"Thusday"; break; } case 5: { cout<<"Friday"; break; } case 6: { cout<<"Saturday"; break; } case 7: { cout<<"Sunday"; break; } default: { cout<<"Invalid No. entered"; } } getch(); } #include <iostream.h> 2 #include <conio.h> void main() { char ch; cout<<"Enter a single character="; cin>>ch; switch(ch) { case'a': case'A': case'e': case'E': case'i': case'I': case'o': case'O': case'u': case'U': { cout<<"It is a vowel"; break; } default: { cout<<"It is constant"; } } getch(); } #include <iostream.h> 3 #include <conio.h> void main() { int marks; cout<<"Enter your marks in %age as 1 for more than 60%, 2 for less than 60%"; cin>>marks; switch(marks) { case 1: { cout<<"You are Eligible for admission."; break; } default: { cout<<"You are not Eligible for admission."; } } getch(); } #include <iostream.h> 4 #include <conio.h> void main() { int game; cout<<"Enter a number(1-9) to see your Future"; cin>>game; switch(game) { case 1: { cout<<"You wiil remain Happy"; break; } case 2: { cout<<"You wiil remain Sad"; break; } case 3: { cout<<"You wiil remain Enjoful"; break; } case 4: { cout<<"You wiil remain Lazy"; break; } case 5: { cout<<"You wiil remain Charming"; break; } case 6: { cout<<"You wiil remain ILL"; break; } case 7: { cout<<"You wiil remain Angry"; break; } case 8: { cout<<"You wiil remain Alone"; break; } default: { cout<<"You wiil remain Healthy"; } } getch(); } #include <iostream.h> 5 #include <conio.h> void main() { int stars; cout<<"Enter 5 to print five,10 for 10 & 15 for 15 stars="; cin>>stars; switch(stars) { case 5: { cout<<"*****"; break; } case 10: { cout<<"**********"; break; } default: { cout<<"***************"; } } getch(); }
  • 5.
    #include <iostream.h> 1 #include<conio.h> void main() { int sum=0; for(int a=1;a<=5;a++) { sum+=a; } cout<<"Sum="<<sum; getch(); } #include <iostream.h> 2 #include <conio.h> void main() { int num; num=1; while(num<=15) { cout<<'n'<<" Hello World "; num++; } getch(); }#include <iostream.h> 3 #include <conio.h> void main() { int square,cube,n; n=2; cout<<"No.tSquaretCuben"; while(n<=7) { cout<<n<<'t'<<n*n<<'t'<<n*n*n<<'t'<<endl; n++; } getch(); } #include <iostream.h> 4 #include <conio.h> void main() { long n; n=3; while(n<=715) { cout<<n<<'t'; n*=5; n++; } getch(); } #include <iostream.h> 5 #include <conio.h> void main() { long c,t,n; cout<<"Enter a no. for table="; cin>>n; t=1; while(t<=10) { c=n*t; cout<<n<<"*"<<t<<"="<<c<<'n'; t++; } getch(); } #include <iostream.h> 6 #include <conio.h> void main() { long r,n; cout<<"Enter any no.="; cin>>n; while(n>0) { r=n%10; cout<<r; n=n/10; } getch(); } #include <iostream.h> 7 #include <conio.h> void main() { float marks; char st_name[25],st_address[15],opt; do { cout<<"Enter name of student="; cin>>st_name; cout<<"Enter address of student="; cin>>st_address; cout<<"Enter obtained marks="; cin>>marks; cout<<"Student record is="<<endl; cout<<st_name<<'t'<<st_address<<'t'<<marks<<endl; cout<<"More Record [Y/N]?"; cin>>opt; } while(opt=='y'||opt=='Y'); { cout<<"OK"; } getch(); } 8 #include <iostream.h> #include <conio.h> void main() { int n,tab; cin>>tab; n=1; do { cout<<n<<"X"<<tab<<"="<<tab*n<<endl; n++; } while(n<=10); getch(); } #include <iostream.h> 9 #include <iostream.h> 10
  • 6.
    C++ Programs ofNested loop Structure #include <iostream.h> 1 #include <conio.h> void main() { unsigned long n,p; for(n=1,p=1;n<=10;n++) { if(n%2==1) { p=p*n; cout<<n<<endl; } } cout<<"Product of odd no's="<<p; getch(); } #include <iostream.h> 2 #include <conio.h> void main() { int n; for(n=2;n<=50;n++) { if(n%2==0) { cout<<n<<'t'; } } getch(); } #include <iostream.h> 3 #include <conio.h> void main() { int a=10; char y; do { for(int i=1;i<=10;i++) { cout<<a<<"*"<<i<<"="<<a*i<<endl; } cout<<"for repeat Y"; cin>>y; } while(y=='y' || y=='Y'); getch(); } #include <iostream.h> 4 #include <conio.h> void main() { int a=10; char y; do { for(int i=1;i<=10;i++) { cout<<"*"<<endl;; } cout<<"for repeat Y "; cin>>y; } while(y=='y' || y=='Y'); getch(); } #include <iostream.h> 5 #include <conio.h> void main() { int a=11; char y; do { for(int i=1;i<=11;i++) { cout<<"This is nested loop"<<endl;; } cout<<"for repeat Y "; cin>>y; } while(y=='y' || y=='Y'); getch(); } #include <iostream.h> 6 #include <conio.h> void main() { int a=2; char y; do { do { for(int i=1;i<=10;i++) { cout<<a<<"X"<<i<<"="<<a*i<<endl;; } cout<<"for repeat Y "; cin>>y; } while(y=='y' || y=='Y'); cout<<"for again repeat y "; cin>>y; } while(y=='Y' || y=='Y'); getch(); }