1.

Banking Program

#include<iostream> #include<string.h> using namespace std;

class bankaccount {

public: char name[20]; long accno; int acctype; double balance;

int assign(); int deposit(); int withdraw(); int display();

};

int main() {

bankaccount obj;

int bankaccount::assign() { cout<<"enter name\naccount no.\n1:savings acccount\t2:current account"; gets(obj.name);

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; }

2.To check whether a number is Armstrong number or not #include<iostream.h> #include<conio.h>

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;

cout << "Enter a number: "; cin >> num;

temp=num; while(num){ i=1,f=1; r=num%10;

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; }

7a)Swap numbers using call by reference
#include<iostream.h> void swap(int &iNum1, int &iNum2); void main() { int iVar1, iVar2; cout<<"Enter two numbers "<<endl; cin>>iVar1; cin>>iVar2; swap(iVar1, iVar2); cout<<"In main "<<iVar1<<" "<<iVar2<<endl; } void swap(int &iNum1, int &iNum2) { int iTemp; iTemp = iNum1; iNum1 = iNum2; iNum2 = iTemp; cout<<"In swap "<<iNum1<<" "<<iNum2<<endl; } 7b) Swap numbers using call by value #include<iostream.h> void swap(int iNum1, int iNum2); void main() { int iVar1, iVar2; cout<<"Enter two numbers "<<endl; cin>>iVar1; cin>>iVar2; swap(iVar1, iVar2); } void swap(int iNum1, int iNum2) { int iTemp; iTemp = iNum1; iNum1 = iNum2; iNum2 = iTemp; cout<<"In swap "<<iNum1<<" "<<iNum2<<endl; }

8.Function Overloading

#include <iostream>

using namespace std;

long add(long, long); float add(float, float);

int main() { long a, b, x; float c, d, y;

cout << "Enter two integers\n"; cin >> a >> b;

x = add(a, b);

cout << "Sum of integers: " << x << endl;

cout << "Enter two floating point numbers\n"; cin >> c >> d;

y = add(c, d);

cout << "Sum of floats: " << y << endl;

return 0; }

long add(long x, long y) { long sum;

sum = x + y;

return sum; }

float add(float x, float y) { float 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; }

void stock_remaining() { left=total-sold; }

void display() { cout<<"Count of items sold"<<sold<<endl; cout<<"Remaining items are:"<<left<<endl; }

}; int shop::total=1000;

static void showtotal() { cout<<"Total"; }

int main() { shop items; items.sold_items();

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;

}

}; int main() { shop items; items.sold_items(); items.stock_remaining(); items.display(); return 0; }

12. To check whether a string is palindrome or not #include <iostream> #include <string>

using namespace std;

int main() { char str[100];

cout << "Enter word :"; cin >> str; int x = strlen(str)-1; for(int i = 0; i <= x; i++) { if (str[i] == str[x-i]) { continue;

} else { cout<<"Not a palidrome"<<endl; return 0; } }

cout << "Indeed Palidrome"<<endl; return 0; }