C++ Programming

Q-1- WAP to find sum and average marks of a student.

#include<iostream.h>
#include<conio.h>
void main()
{  int a,b,c,d,e,sum;
  float avg;
  clrscr();
  cout<<"ENTER MARKS OF FIVE SUBJECTS:";
  cin>>a>>b>>c>>d>>e;
  sum=a+b+c+d+e;
  cout<<"SUM OF FIVE SUBJECTS="<<sum;
  avg=sum/5;
  cout<<"\nAVERAGE="<<avg;
  getch();
};




OUT PUT 1-








Q-2- WAP to convert Fahrenheit to Celsius temperature.
#include<iostream.h>
#include<conio.h>
void main()
{ float fah,cel;
  clrscr();
  cout<<"ENTER TEMPERATURE IN FAHRENHEIT:";
  cin>>fah;
  cel=(5/9)*(fah-32);
  cout<<"TEMPERATURE IN CELSIUS IS "<<cel;
  getch();
  };


OUT PUT 2-






Q-3- WAP to find greatest out of two numbers.
#include<iostream.h>
#include<conio.h>
void main()
{ int a,b;
  clrscr();
  cout<<"ENTER TWO NUMBERS:";
  cin>>a>>b;
  if(a>b)
  cout<<"BIGGEST NUMBER IS "<<a;
  else
  cout<<"BIGGEST NUMBER IS "<<b;
  getch();
};           



OUT PUT 3-






Q-4- WAP for the admission to a
   Professional course in subject
   to the following condition:
   1. Marks in math>=60
   2. Marks in physics>=50
   3. Marks in chemistry>=40
   4. Total marks>=200
#include<iostream.h>
#include<conio.h>
void main()
{ int a,b,c,sum;
  clrscr();
  cout<<"ENTER YOUR MARKS IN PHYSICS:";
  cin>>a;
  cout<<"ENTER YOUR MARKS IN CHEMISTRY:";
  cin>>b;
  cout<<"ENTER YOUR MARKS IN MATHEMATICS:";
  cin>>c;
  sum=a+b+c;
  cout<<"YOUR GRAND TOTAL="<<sum;
  if(a>=50&&b>=40&&c>=60&&sum>=200)
  cout<<"\n\nCONGRATULATIONS!!!"<<"\nYOU ARE ELIGIBLE FOR ADMISSION";
  else
  cout<<"\n\nSORRY!!!"<<"\nYOU ARE NOT ELIGIBLE FOR ADMISSION";
  getch();
};
OUT PUT 4-



Q-5- WAP of swapping of two number using third variable.
#include<iostream.h>
#include<conio.h>
void main()
{ int a,b,temp;
  clrscr();
  cout<<"ENTER TWO NUMBERS"<<"\nA=";
  cin>>a;
  cout<<"B=";
  cin>>b;
  temp=a;
  a=b;
  b=temp;
  cout<<"\nAFTER SWAPPING";
  cout<<"\nA="<<a;
  cout<<"\nB="<<b;
  getch();
};


OUT PUT 5-




Q-6- WAP to print all prime number less then 100.
#include<iostream.h>
#include<conio.h>
void main()
{ int n,i;
  clrscr();
  cout<<"ALL PRIME NUMBERS BETWEEN 1 TO 100 ARE:";
  for(n=3;n<=100;n++)
  { i=2;
   while(i<=n-1)
   { if(n%i==0)
     break;
     i++;
   }
   if(i==n)
   cout<<"\n"<<n;
  }
   getch();
};

OUT PUT 6-






Q-7- WAP for factorial of a number.
#include<iostream.h>
#include<conio.h>
void main()
{ int a,i,fact=1;
  clrscr();
  cout<<"ENTER NUMBER:";
  cin>>a;
  for(i=1;i<=a;i++)
  { fact=fact*i;
  }
  cout<<"FACTORIAL OF A GIVEN NUMBER IS "<<fact;
  getch();
};


OUT PUT 7-




Q-8- WAP to print Fibonacci series.
#include<iostream.h>
#include<conio.h>
void main()
{ int x,i,y,a=0,b=1;
  clrscr();
  cout<<"ENTER HOW MANY NUMBERS YOU WANT:";
  cin>>x;
  for(i=0;i<x;i++)
  { y=a+b;
    cout<<"\n"<<y;
    a=b;
    b=y;
  }
  getch();
};


OUT PUT 8-




Q-9- WAP to check number is even or odd.
#include<iostream.h>
#include<conio.h>
void main()
{ int a;
  clrscr();
  cout<<"ENTER NUMBER:";
  cin>>a;
  if(a%2==0)
  cout<<"GIVEN NUMBER IS EVEN";
  else
  cout<<"GIVEN NUMBER IS ODD";
  getch();
};


OUT PUT 9-




Q-10- WAP to check input is palindrome or not.
#include<iostream.h>
#include<conio.h>
void main()
{ int n,num,digit,rev=0;
  clrscr();
  cout<<"ENTER NUMBER:";
  cin>>num;
  n=num;
  do
  { digit=num%10;
    rev=(rev*10)+digit;
    num=num/10;
  }
  while(num!=0);
  cout<<"THE REVERSE OF A NUMBER IS:"<<rev<<"\n";
  if(n==rev)
  cout<<"THE NUMBER IS PALINDROME";
  else
  cout<<"\n THE NUMBER IS NOT A PALINDROME";
  getch();
};
OUT PUT 10-




Q-11- WAP to find area and parameter of a circle,rectangle,triangle and square.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{ float area,peri,r,l,b,x,y,z,w;
  int ch;
  clrscr();
  cout<<"PRESS 1 FOR AREA";
  cout<<"\nPRESS 2 FOR PERIMETER";
  cout<<"\nENTER YOUR CHOICE:";
  cin>>ch;

  if(ch==1)
  { cout<<"\n\t AREA MENU\n";
    cout<<"\nPRESS 1 FOR AREA OF CIRCLE";
    cout<<"\nPRESS 2 FOR AREA OF RECTANGLE";
    cout<<"\nPRESS 3 FOR AREA OF TRIANGLE";
    cout<<"\nPRESS 4 FOR AREA OF SQUARE";
    cout<<"\nENTER YOUR CHOICE:";
    cin>>ch;

    switch(ch)
    { case 1:cout<<"\nENTER THE RADIUS OF A CIRCLE:";
               cin>>r;
               area=3.14*r*r;
               cout<<"\nAREA OF CIRCLE IS "<<area;
               break;
      case 2:cout<<"\nENTER LENGTH AND BREATH OF A RECTANGLE:";
               cin>>l>>b;
               area=l*b;
               cout<<"\nAREA OF RECTANGLE IS "<<area;
               break;
      case 3:cout<<"\nENTER THE THREE SIDE OF A TRIANGLE:";
               cin>>x>>y>>z;
               w=(x+y+z)/2;
               area=sqrt(w*(w-x)*(w-y)*(w-z));
               cout<<"\nAREA OF TRIANGLE IS "<<area;
               break;
      case 4:cout<<"\nENTER THE SIDE OF SQUARE:";
               cin>>w;
               area=w*w;
               cout<<"\nAREA OF A SQUARE IS "<<area;
               break;
      default:cout<<"\nWRONG CHOICE!!!";
               break;
      }
  }
  else if(ch==2)
  { cout<<"\n\tPERIMETRE OF A CIRCLE";
    cout<<"\nPRESS 1 FOR PERIMETRE OF CIRCLE";
    cout<<"\nPRESS 2 FOR PERIMETRE OF RECTANGLE";
    cout<<"\nPRESS 3 FOR PERIMETRE OF TRIANGLE";
    cout<<"\nPRESS 4 FOR PERIMETRE OF SQUARE";
    cout<<"\nENTER YOUR CHOICE:";
    cin>>ch;

  switch(ch)
  { case 1:cout<<"\nENTER THE RADIUS OF A CIRCLE:";
             cin>>r;
             peri=3.14*r*2;
             cout<<"\nPERIMETRE OF A CIRCLE IS "<<peri;
             break;
    case 2:cout<<"\nENTER LENGTH AND BREATH OF RECTANGLE:";
             cin>>l>>b;
             peri=2*(l+b);
             cout<<"\nPERIMETRE OF RECTANGLE IS "<<peri;
             break;
    case 3:cout<<"\nENTER THREE SIDES OF TRIANGLE:";
             cin>>x>>y>>z;
             peri=x+y+z;
             cout<<"\nPERIMETRE OF TRIANGLE IS "<<peri;
             break;
    case 4:cout<<"\nENTER THE SIDE OF SQUARE:";
             cin>>w;
             peri=4*w;
             peri=4*w;
             cout<<"\nPERIMETRE OF SQUARE IS "<<peri;
             break;
    default:cout<<"\nWRONG CHOICE!!!";
              break;
   }
  }
  else
  cout<<"\nYOU HAVE ENTERDE WRONG CHOICE!!!";
   getch();
};


OUT PUT 11-




Q-12- WAP to print pyramid of a number.
#include<iostream.h>
#include<conio.h>
void main()
{ int i,j,k,l,m=5;
  clrscr();
  for(i=1;i<m;i++)
  { for(j=1;j<=m-i;j++)
    { cout<<" ";
    }
    for(k=1;k<=i;k++)
    { cout<<k;
    }
    for(l=i-1;l>=1;l--)
    { cout<<l;
    }
    cout<<"\n";
  }
  getch();
};
OUT PUT 12-





Q-13- WAP to enter name and age of a person and display using class.
#include<iostream.h>
#include<conio.h>
class person
{ char name[30];
  int age;
  public:
  void getdata();
  void dispdata();
};
 void person::getdata()
 { cout<<"ENTER YOUR NAME:";
   cin>>name;
   cout<<"ENTER YOUR AGE:";
   cin>>age;
 }
 void person::dispdata()
 { cout<<"\nYOUR NAME IS "<<name;
   cout<<"\nYOUR AGE IS "<<age;
 }

 void main()
 { clrscr();
   person a;
   a.getdata();
   a.dispdata();
   getch();
 }
OUT PUT 13-





Q-14- WAP to calculate and display sum,average and percentage of a student’s marks.
#include<iostream.h>
#include<conio.h>
class marks
{ int a,b,c,d,e,sum;
  float avg,per;
  public:
  void getdata();
  void dispdata();
};
 void marks::getdata()
 { cout<<"ENTER MARKS OF FIVE SUBJECTS:";
   cin>>a>>b>>c>>d>>e;
   sum=a+b+c+d+e;
   avg=sum/5;
   per=sum/5;
 }
 void marks::dispdata()
 { cout<<"\nSUM IS "<<sum;
   cout<<"\nAVERAGE IS "<<avg;
   cout<<"\nYOUR PERCENTAGE="<<avg;
 }

 void main()
 { clrscr();
   marks m;
   m.getdata();
   m.dispdata();
   getch();
 }


OUT PUT 14-


1 comment:

  1. Great resources on C++ programming! Mastering this language is as vital as using hekateswitch for optimizing your gaming performance!

    ReplyDelete

FEEDBACK

Name

Email *

Message *