Banking Program
class bankaccount {
};
int main() {
bankaccount obj;
cin>>obj.accno>>obj.acctype; balance=0.0; } int bankaccount::deposit() { cout<<"enter amount to be deposited"; cin>>obj.balance; } int bankaccount::withdraw() { cout<<"current account balance:"<<balance<<endl; cout<<"enter amount to be withdrawn"; double withdraw; cin>>withdraw; if(withdraw<=obj.deposit) obj.balance-=withdraw; else cout<<"insufficient balance"; } int bankaccount::display() { puts(obj.name); cout<<"account balance:"<<obj.balance<<endl; } return 0; }
void main() { int Number,Temp,b=0; cout<<endl<<"Enter any number to check"; cin>>Number; Temp=Number; int P; while(Temp>0) { P=Temp%10; b=b P*P*P; Temp=Temp/10; } if(b==Number) { Cout<<endl<<"Armstrong no"; } else { cout<<"Not an armstrong no"; } getch(); } 3.To check whether a given number is palindrome or not #include<iostream.h> #include<conio.h> void main()
{ clrscr(); long int n,rev=0,m,num; cout<<"please enter a five digit no.: "; cin>>n; num=n; while(n>0) { m=n%10; rev=rev*10+m; n=n/10; } cout<<rev<<endl; if (num==rev) cout<<"Number is a palindrome"; else cout<<"Not a palindrome"; getch(); } 4. An electricity board charges the following rates to domestic users to discourage
the wastage of electricity. For the first 100 units: 60 P/unit. For the next 200 units: 80 P/unit. Beyond 300 units: 90 P/unit. All users are charged a minimumof Rs 50. If the total amount is more than Rs300 then additional surcharge of 15% is added. Write a program to read the names of users and number of units consumed and print the total charges with names of consumers.
#include<iostream.h> #include<conio.h>
void main() { clrscr(); cout<<"\n\n\n\tElectricity Board Charges\n"; cout<<"\n\tTo Discourage Large Consumption of energy\n\n";char name[20]; cout<<"\n\nEnter USER name :-"; cin>>name; cout<<"\n\nEnter Number of Units Consumed:-"; float unit; cin>>unit; float tc; if(unit<=100) tc=unit*0.60; else if(unit<=300) tc=unit*0.80; else tc=unit*0.90; float surchase=0; if(tc>300) surchase=tc*0.15; float total_cost; total_cost = 50 + surchase + tc; cout<<"\n\nYOUR BILL AMOUNT IS "<< total_cost; getch(); } 5. To add two objects
#include<iostream>
using namespace std; class data { int a,b; public: int sum; void getdata(int a,int b); void display(); }; void data::display() { cout<<"sum of a and b="<<sum; } void data::getdata(int a,int b) { sum=a+b; } int main() { data d; d.getdata(20,11); d.display(); return 0; }
6.to check whether a number is strong or not #include<iostream> int main(){ int num,i,f,r,sum=0,temp;
while(i<=r){ f=f*i; i++; } sum=sum+f; num=num/10; } if(sum==temp) cout << temp << " is a strong number"; else cout << temp << " is not a strong number";
return 0; }
8.Function Overloading
#include <iostream>
x = add(a, b);
cout << "Enter two floating point numbers\n"; cin >> c >> d;
y = add(c, d);
return 0; }
sum = x + y;
return sum; }
sum = x + y;
return sum; } 9. To swap private member values of class by using friend function #include<iostream.h> #include<conio.h> class XYZ; class ABC; {
int a; public; void setdata(int m) { a=m; } Friend void exchange(ABC & X,XYZ &W); void display data() { cout<"a= "<<a; } }; class XYZ; class XYZ; { int b; public: void setdata(int n) { b=n; } friend void exchange(ABC&X,XYZ &W); void displaydata() { cout<<"b= "<<b; } };
void exchange(ABC & value 1,XYZ & value 2) { int temp; temp=value 1.a; value 1.a=value 2.b; value 2.b=temp; }; void main() { ABC m; m.setdata(10); XYZ n; n.setdata(20); cout<<"values before exchange"; m.display data(); n.display data(); exchange(m,n); cout<<"values after exchange"; m.display data(); n.display data(); } 10. WAP to print the count of items sold and remaining stock separately, in a shopping mall (in
a day). Create a class shop having member functions sold_items and stock_remaining. Use static member data wherever required.(using static members) #include<iostream> using namespace std;
class shop {
int sold; int left; static int total; public: void sold_items() { cout<<"Enter the number of sold items"<<endl; cin>>sold; }
}; int shop::total=1000;
items.stock_remaining(); items.display(); return 0; } 11.write the same program without using static members #include<iostream> using namespace std;
class shop { int sold; int left; int total; public: void sold_items() { cout<<"Enter the number of sold items"<<endl; cin>>sold; }
void stock_remaining() { total=1000; left=total-sold; } void showtotal() { cout<<"Total"; } void display() { cout<<"Count of items sold"<<sold<<endl; cout<<"Remaining items are:"<<left<<endl;
12. To check whether a string is palindrome or not #include <iostream> #include <string>
cout << "Enter word :"; cin >> str; int x = strlen(str)-1; for(int i = 0; i <= x; i++) { if (str[i] == str[x-i]) { continue;
cout << "Indeed Palidrome"<<endl; return 0; } 13. Create payroll system using single inheritance #include<iostream>
#include<cstring>
class employee
public:
string name;
double yoj;
int age;
void getdata();
};
{ double basic;
double allowance;
double bonus;
public :
//void get();
void display();
double tot();
};
void employee ::
getdata()
cout << "enter year of joining" << endl; cin>> yoj; cout << "enter the age " << endl; cin >> age;
cout << name << endl << yoj << endl << age << endl;
cout << "the salary of "<< name << " is " << sal;
cin >> basic; cout << "enter the total allowance" << endl; cin >> allowance;
cout << "enter the bonus if any" << endl; cin >> bonus ;
return sum;
int main()
{ salary s;
s.getdata();
s.display();
return 0;
int main()
{ char c='A';
for(int i=1;i<=5;i++)
for(int j=5;j>i;j--)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<c<<" ";
c++;
cout<<endl;
return 0;
15.Remove duplicates from the string #include<iostream> #include<string> #include<cstring> using namespace std; main () { int i; int j=0; string s; cout << "enter the string " << endl; cin >> s; int l = s.length(); for(i=0;i<l;i++) { for(j=i+1;j<l;)
{ if(s[j]==s[i]) { for(int k=j;k<l;k++) s[k]=s[k+1]; l--; } else j++; } } cout << "the string after removing duplicates is" << endl << s; }
#define R 3
#define C 6
int i, k = 0, l = 0;
cout<< a[k][i];
k++;
cout<< a[i][n-1];
n--;
if ( k < m)
cout<< a[m-1][i];
m--;
if (l < n)
cout<< a[i][l];
l++;
int main()
{ i nt a[R][C] = { {1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18} };
spiralPrint(R, C, a);
return 0;
int main()
char c='A';
for(int i=1;i<5;i++)
for(int j=5;j>i;j--)
cout<<" ";
for(int k=1;k<=i*2-1;k++)
cout<<c;
c++;
cout<<endl;
return 0;
} 18. //WAP to print student's status of academic and sport activities by forming the three classes namely student, sports. Use multiple inheritance and assume the required data.
#include<iostream>
#include<cstring>
class acad
public:
string branch;
float cg;
void getdata();
};
class sport
};
public :
void display();
};
cout << "enter the cgpa " << endl; cin >> cg;
cout << "enter the sport name " << endl; cin>> sport;
cout << "enter the year " << endl; cin >> year;
cout<<endl << name << endl << branch << endl << year << endl << cg << endl << sport << endl;
int main() {
student s;
s.getdata(); s.get();
s.display();
return 0;
} 19. Program to calculate the marks secured by a student.A Parent class with student identification is created and another class called marks is inherited from the main class.This class marks is further inherited by another class called sports and finally the sports class is inherited by the percentage class to calculated the percentage of marks.
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class student_id { int rno; char name[20]; public: void read_id()
{ cout<<"\n\nEnter the Name of the Student : "; gets(name); cout<<"\n\nEnter the Roll No. : "; cin>>rno; } void display_nr() { cout<<"\n\n\t\tSTUDENT REPORT\n\nNAME : "; puts(name); cout<<"\n\nROLL NO. : "<<rno; } }; class marks:public student_id { public: int i,mark[3]; void read_m() { read_id(); for(i=0;i<3;i++) { cout<<"\n\nEnter the Marks Secured in SUBJECT "<<i+1<<" out of 100 : "; cin>>mark[i]; } } void display_m()
{ display_nr(); cout<<"\n\n\tMarks Secured "; for(i=0;i<3;i++) cout<<"\n\nSUBJECT "<<i+1<<" : "<<mark[i]; } }; class sports { public: int sm; void read_sportm() { cout<<"\n\nEnter the marks in SPORTS out of 10 : "; cin>>sm; } }; class percentage:public marks,public sports { public: float total,prcntge; void calculate() { read_m(); read_sportm(); total=0; for(i=0;i<3;i++)
{ total+=mark[i]; } total+=sm; prcntge=(total/310)*100; } void display_totp() { display_m(); cout<<"\n\nTOTAL = "<<total; cout<<"\n\nPERCENTAGE = "<<prcntge; } }; void main() { int cont; percentage pc; clrscr(); do { pc.calculate(); clrscr(); pc.display_totp(); cout<<"\n\nDo You Want to Continue?(1-YES/0-NO)"; cin>>cont; }while(cont==1); getch();