Following are the list of C++ Programs.
1. C++ Program to display employee salary information.
#include<iostream.h> #include<conio.h> class test { public: int bs, hra, pf, net; getdata(int bs1, int hra1, int pf1) { bs=bs1; hra=hra1; pf=pf1; net=bs+hra-pf; return(net); } void display() { cout <<"Net Salary="<<net; } }; main() { clrscr(); test t; t.getdata(10000,3000, 1500); t.display(); }
2. C++ Program to add 2 numbers.
#include<iostream.h> #include<conio.h> void main() { int a,b; clrscr(); cout<<"\nEnter two numbers:"; cin>>a>>b; int sum=a+b; cout<<"\nResult="<<sum; getch(); }
3. C++ Program to display square and cube of entered number.
#include<iostream.h> #include<math.h> #include<conio.h> main() { int num; clrscr(); cout<<"\nEnter number:"; cin>>num; cout<<"\nSquare of the given number="<<num*num; cout<<"\nCube of the given number="<<num*num*num; cout<<"\nSquare root of the given number="<<sqrt(num); getch(); }
4. C++ Program to show inventory information.
#include<iostream.h> #include<conio.h> main() { int qty; char itemnm[15]; float price,tot; clrscr(); cout<<"\nEnter item name:"; cin>>itemnm; cout<<"\nEnter qty:"; cin>>qty; cout<<"\nEnter price:"; cin>>price; tot=qty*price; clrscr(); cout<<"\n=====BILL====="; cout<<"\nItem name:"<<itemnm; cout<<"\nQty :"<<qty; cout<<"\nPrice :"<<price; cout<<"\nTotal Amt:"<<tot; cout<<"\n=============="; getch(); }
5. C++ program to display addition and multiplication using switch case.
#include<iostream.h> #include<conio.h> main() { int a,b,ch; clrscr(); cout<<"\n1.Addition"; cout<<"\n2.Multilplication"; cout<<"\nEnter choice:"; cin>>ch; switch(ch) { case 1: cout<<"\nResult="<<a+b; break; case 2: cout<<"\nResult="<<a-b; break; default: cout<<"\nInvalid choice"; break; } getch(); }
6. C++ Program to use goto statement.
#include<iostream.h> #include<conio.h> main() { int i; clrscr(); for(i=1;i<=10;i++) { if(i==5) goto a; cout<<"\nI="<<i; } a: cout<<"\nProgram terminated"; getch(); }
7. C++ Program to display smallest and largest number.
#include<iostream.h> #include<conio.h> main() { int num[10]; int range; clrscr(); cout<<"\nEnter range:"; cin>>range; cout<<"\nEnter "<<range<<" numbers:"; for(int i=0;i<range;i++) cin>>num[i]; cout<<"\nThe given numbers are:"; for(i=0;i<range;i++) cout<<"\n"<<num[i]; int big,small; big=num[0]; small=num[0]; for(i=1;i<range;i++) { if(num[i]>big) big=num[i]; else if(num[i]<small) small=num[i]; } cout<<"\nLargest number="<<big; cout<<"\nSmallest number="<<small; getch(); }
8. C++ Program to swap 2 numbers using function.
#include<iostream.h> #include<conio.h> swap(int,int); main() { int a,b; clrscr(); cout<<"\nEnter two numbers:"; cin>>a>>b; cout<<"\nBefore calling the function"; cout<<"\nA="<<a; cout<<"\nB="<<b; swap(a,b); cout<<"\nAfter calling the function"; cout<<"\nA="<<a; cout<<"\nB="<<b; getch(); } swap(int a,int b) { int temp=a; a=b; b=temp; cout<<"\nInside the function"; cout<<"\nA="<<a; cout<<"\nB="<<b; }
9. C++ Program to find length of the string.
#include<iostream.h> #include<conio.h> #include<string.h> main() { char str[25]; int i,len=0; clrscr(); cout<<"\nEnter string:"; cin>>str; for(i=0;str[i]!='\0';i++) { len++; } cout<<"\nLength of the string="<<len; getch(); }
10. C++ Program to calculate electricity bill.
#include<iostream.h> #include<conio.h> class EBill { int meterno,units,tot; char cnm[15]; public: void getInfo() { cout<<"\nEnter customer name:"; cin>>cnm; cout<<"\nEnter number of units used:"; cin>>units; cout<<"\nEnter meter number:"; cin>>meterno; } void calc() { if(1<= units<=150) tot=units*2+100; else if(150< units<=300) tot=units*3+100; else if(300< units<=400) tot=units*4+100; else tot=units*5+100; } void showBill() { cout<<"\n=====Electricity BILL======"; cout<<"\nCustomer name="<<cnm; cout<<"\nNo. of Units ="<<units; cout<<"\nMeter number ="<<meterno; cout<<"\nTotal Bill ="<<tot; cout<<"\n================"; } }; main() { clrscr(); EBill ob; ob.getInfo(); ob.calc(); ob.showBill(); getch(); }
Thank you for referring above programs.
keep subscribe to latest and updated programs.