



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Best oops notes for colleges includes class
Typology: Lecture notes
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















#include
#include
class Account { char name[30]; int acno; char type; float balance; public: void initial(){ cout<<"Enter name: "; cin>>name; cout<<"Enter Account No: "; cin>>acno; cout<<"Enter account type: "; cin>>type; cout<<"Enter intial amount: "; cin>>balance; } void deposit(float amount){ balance = balance + amount; } void withdraw(float amount){ char opt; cout<<"Current balance: "<<balance<<endl; cout<<"Are you sure to withdraw? (y/n)"; cin>>opt; if(opt == 'y' ){ if(balance-amount >= 10000){ balance = balance - amount; }else{ cout<<"Insufficient balance! \a\a\a"; } }
return 0; }
#include
class test { int code; static int count;
public: void setcode(void) { code = ++count; } void showcode(void) { cout << "object number :" << code << "\n"; } static void showcount(void) { cout << "count:" << count << "\n"; } }; int test::count; int main() { test t1, t2; t1.setcode(); t2.setcode();
test::showcount();
test t3; t3.setcode();
test::showcount(); t1.showcode(); t2.showcode(); t3.showcode(); return 0; }
int main() { char ch='y'; int i=0,dur,no; serial s1[10]; while(ch=='y') { s1[i].newserial(); cout<<"Enter the duration and the no. of episodes:"; cin>>dur>>no; s1[i].otherentries(dur,no); i++; cout<<"\n\nDo you want to continue:"; cin>>ch; } cout<<"\n\nThe details you have entered are:"<<endl<<endl; for(int j=0;j<i;j++){ cout<<"Data of serial "<<j+1<<" is:"<<endl; s1[j].displaydata(); } return 0; }
#include
struct Name { char First[40]; char Mid[40]; char Last[60]; };
struct Phone { char Area[40]; charExch[40]; char Numb[60]; }; class employee{ Name name; Phone p_rec; public: employee(){ strcpy(name.First,"\0"); strcpy(name.Mid,"\0"); strcpy(name.Last,"\0"); strcpy(p_rec.Area,"\0"); strcpy(p_rec.Exch,"\0"); strcpy(p_rec.Numb,"\0"); }
voidset_name(char *nf,char *nm,char *nl){ strcpy(name.First,nf); strcpy(name.Mid,nm); strcpy(name.Last,nl); } void set_val1(char *nf,char *nm,char *nl){ strcpy(p_rec.Area,nf); strcpy(p_rec.Exch,nm); strcpy(p_rec.Numb,nl); } void input(){ cout<<"enter first name\n"; cin.getline(name.First,40); cout<<"enter you mid name\n"; cin.getline(name.Mid,40); cout<<"enter your last name\n"; cin.getline(name.Last,60);
cout<<" Height : "<<height<<endl; cout<<" Width : "<<width<<endl; cout<<" Depth : "<<depth<<endl; } };
class Carton : public Box { int weight; public: void input_carton() { cout<<"Enter weight "; cin>>weight; } void display_carton() { cout<<"Carton : "; cout<<weight<<endl; } };
int main() {
Carton c; c.input_box(); c.input_carton(); cout<<"Displaying Details :\n"; c.display_box(); c.display_carton();
}
#include
class derived:public base { public:
switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: if(date==31) { date=1; month++; } else { date++; } break; case 4: case 6: case 9: case 11: if(date==30) { date=1; month++; } else { date++; } break; case 12: if(date==31) { date=1; month=1; year++; } else { date++; } break; case 2: if (year % 4 == 0) { if ((year % 100 == 0)&&(year % 400 == 0)) { if(date==29) {
date=1; month++; } else { date++; } } if(date==29) { date=1; month++; } else { date++; } } else { if(date==28) { date=1; month++; } else if(date==29) { cout<<"Invalid Date!"; exit(0); } else { date++; } } break; }
} void showdate() { cout<<"\nTomorrow will be "<<date<<"-"<<month<<"-"<<year; } };
int main() { Date d;
complex temp; temp.a=a+obj.a; temp.b=b+obj.b; return(temp); } int main() { complex c1(5,6),c2(7,8),c3; cout<<"The 1st no. is:"; c1.show(); cout<<"\nThe 2nd no. is:"; c2.show(); c3=c1+c2; cout<<"\nSum is:"; c3.show(); getch(); }
#include
class box { public:
int l,b,h;
box(float a,float e,float c) { l=a; b=e; h=c; } void operator=(const box& d) { l=d.l; b=d.b; h=d.h; } bool operator<(const box& d) {
if((lbh)<(d.ld.bd.h)) return true; else return false; } bool operator <=(const box& d) { if((lbh)<=(d.ld.bd.h)) return true; else return false; } bool operator >(const box& d) { if((lbh)>(d.ld.bd.h)) return true; else return false; } bool operator >=(const box& d) { if((lbh)>=(d.ld.bd.h)) return true; else return false; } bool operator==(const box& d) { if((lbh)==(d.ld.bd.h)) return true; else return false; } };
int main() { box b1(2,3,4),b2(5,6,7); bool accept; cout<<"Before applying b1=b2\n"; if(b1<b2) cout<<"b1<b2"; if(b1>b2) cout<<"\nb1>b2"; cout<<"\nAfter applying b1=b2"; b1=b2; if(b1>=b2) cout<<"\nb1>=b2";
getch(); } int area(int s) { return(ss); } int area(int l,int b) { return(lb); } float area(float r) { return(3.14rr); } float area(float bs,float ht) { return((bs*ht)/2); }
#include<iostream.h> #include<conio.h> class shape { public: double x,y; virtual void getdata()=0; virtual void area()=0; }; class circle:public shape { public: double are; int aa; void getdata() { cout<<"\nenter the radius"; cin>>aa; } void area() { are=(3.14 aaaa); } void display() {
cout<<"area of circle is"<< are; } }; class rectangle:public shape { public: double are; int aa,bb; void getdata() { cout<<"\nenter the length and breadth"; cin>>aa>>bb; } void area() { are=(aa*bb); } void display() { cout<<"area of rectangle is"<< are; }
}; class triangle:public shape { public: double are; int aa,bb; void getdata() { cout<<"\nenter the base and height of triangle "; cin>>aa>>bb; } void area() { are=(0.5bbaa); } void display() { cout<<"area of triangle is"<< are; } }; int main() { shape *s; circle c; triangle t; rectangle r; clrscr();