Name: Sumeet Lalla ROLL NO: 101203104 Group: Coe-9
Name: Sumeet Lalla ROLL NO: 101203104 Group: Coe-9
1.Banking Program
class bankaccount {
};
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;
#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;
} if(sum==temp) cout << temp << " is a strong number"; else cout << temp << " is not a strong number";
return 0; }
void swap(int iNum1, int iNum2) { int iTemp; iTemp = iNum1; iNum1 = iNum2; iNum2 = iTemp; cout<<"In swap "<<iNum1<<" "<<iNum2<<endl; }
x = add(a, b);
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 { 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;
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; }
12. To check whether a string is palindrome or not #include <iostream> #include <string>
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; } }