You are on page 1of 73

Ques 1: Write a program to evaluate the following investment equation v=p(1+r)n where , P is the principle, V is the value of money

at the end of n years. #include<iostream.h> #include<conio.h> class c_interest { public: float p, r, n, v; c_interest() { cout<<"\n\n\tEnter the principle: "; cin>>p; cout<<"\n\tEnter the rate: "; cin>>r; cout<<"\n\tEnter the years: "; cin>>n; v=1; } void pow() { int i=1; while(i<=n) { v=v*(1+r/100); i++; } v=v*p; } void ci_result() { pow(); cout<<"\n\n\tCompound Interest: "<<v; } }; void main() { clrscr(); c_interest obj; obj.ci_result(); getch();}

Ques 2: An election is contested by 5 candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count. In case, a number read is outside the range of 1 to 5, the ballot should be considered as a spoilt ballot, and the program should also count the number of spoilt ballots.

#include<iostream.h> #include<conio.h> class c_election { public: int count[6], c_spoilt; c_election() { int i=1; while(i<=5) { count[i]=0; i++; } c_spoilt=0; } void r_ballots() { int i=1, id=0; char ch; do { while(i<=5) { cout<<"\n\t"<<i<<" .candidate:"; i++; } cout<<"\n\n\tEnter your choice: "; cin>>id; switch(id) { case 1: cout<<"\n\n\tRead Ballots Successfully....!"; count[id]++;

break; case 2: cout<<"\n\n\tRead Ballots Successfully....!"; count[id]++; break; case 3: cout<<"\n\n\tRead Ballots Successfully....!"; count[id]++; break; case 4: cout<<"\n\n\tRead Ballots Successfully....!"; count[id]++; break; case 5: cout<<"\n\n\tRead Ballots Successfully....!"; count[id]++; break; default:c_spoilt++; cout<<"\n\n\t oops..! spoilt ballot!!!"; } cout<<"\n\n\tDo you want to contnue voting y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); } void v_results() { int i=1; while(i<=5) { cout<<"\n\tCandidate "<<i<<" votes: "<<count[i]; i++; } cout<<"\n\n\t\tSpoilt ballots: "<<c_spoilt; } }; void main() { c_election obj; clrscr(); obj.r_ballots(); obj.v_results(); getch();}

Ques 3: A cricket team has the following table of batting figures for a series of test matches: Players Name Sachin Saurav Rahul Runs 8430 4200 3350 Innings 230 130 105 Times not out 18 9 11

Write a program to read the figures set out in the above form, to calculate the batting averages and to print out the complete table including the averages.

Ques 4: An electricity board charges the following rates to domestic users to discourage large consumption of energy: For the first 100units 60p per unit For next 200 units 80p per unit Beyond 300 units 90p per unit All users are charged a minimum of Rs. 50.00. If the total amount is more then Rs 300.00 then an additional surcharge of 15% is added. Write a program to read the names of users and number of units consumed and print out the charges with names. #include<iostream.h> #include<stdio.h> #include<conio.h> class e_board { public: char name[20]; float c_units, u_charge, u_charge1, u_charge2, total; void d_user() { cout<<"\n\n\tEnter the user's name: "; gets(name); cout<<"\n\tEnter the units consumed: "; cin>>c_units; } void u_charges() {

if(c_units<=100) { u_charge=0.60f*c_units; cout<<"\n\t\tFor 1-100u charge (0.60p p/u): "<<u_charge; if(u_charge<=50) { u_charge=50; cout<<"\n\t\tMinimum Charge apply: "<<u_charge; } cout<<"\n\t\tTotal Charges: "<<u_charge; } else if(c_units>100 && c_units<=300) {

u_charge=0.60f*100; cout<<"\nFor 1-100u charge (0.60p p/u): "<<u_charge; c_units-=100; u_charge1=0.80f*c_units; cout<<"\nFor 101-300u charge (0.80p p/u): "<<u_charge1; total=u_charge+u_charge1; cout<<"\nTotal Charges: "<<total; } else { u_charge=0.60f*100; cout<<"\n\t\tFor 1-100u charge (0.60p p/u): "<<u_charge; c_units-=100; u_charge1=0.80f*200; cout<<"\n\t\tFor 101-300u charge (0.80p p/u): "<<u_charge1; c_units-=200; u_charge2=0.90f*c_units; cout<<"\n\t\tFor 301u-Nu charge (0.90p p/u): "<<u_charge2; total=u_charge+u_charge1+u_charge2; if(total>300) { int a_charge=0.15f*total; cout<<"\n\t\tAdditional charges @15%: "<<a_charge; total+=a_charge; } cout<<"\n\t\tTotal Charges: "<<total; } } void b_details() { cout<<"\n\n\tName: "; puts(name); cout<<"\n\tCharges in details: "; u_charges(); } }; void main() { clrscr(); int num;

e_board obj[100]; cout<<"\n\nEnter the number of consumer: "; cin>>num; for(int i=1;i<=num;i++) { cout<<"\n\nEnter details of "<<i<<" user's\n"; obj[i].d_user(); } for(i=1;i<=num;i++) { cout<<"\n\n\tDetails of "<<i<<" user's:"; obj[i].b_details(); } getch(); }

Ques 5: Write a function power() to raise a number m to a power n. the function takes a double value for m and int value for n, and return the result correctly. Use a default value of 2 for n to make the function to calculate squares when this argument is omitted. Write a main that gets the value of m and n from user to test the function. #include<iostream.h> #include<conio.h> class base_exp { public: int i; double calc; base_exp() { i=1; calc=1; } int power(int n, double m) { if(n<2) { n=2; cout<<"\n\nThe minimum value of n(exp) sould be 2"; cout<<"\nDefault value is initialized to n: "<<n; } while(i<=n) { calc=calc*m; i++; } return calc; } void display() { cout<<"\nResults: "<<calc; } }; void main() { clrscr(); int n; double m;

cout<<"\nEnter the base: "; cin>>m; cout<<"\nEnter the exp: "; cin>>n; base_exp obj; obj.power(n, m); obj.display(); getch(); }

Ques 6: Write a function that performs the same operation as above but takes an int value for m. Both the functions should have the same name. Write a main that calls both the functions. Use the concept of function overloading. #include<iostream.h> #include<conio.h> class base_exp { public: int i; double calc; base_exp() { i=1; calc=1; } int power(int n, double m) { if(n<2) { n=2; cout<<"\n\nThe minimum value of n(exp) sould be 2"; cout<<"\nDefault value is initialized to n: "<<n; } while(i<=n) { calc=calc*m; i++; } return calc; } int power(int n, int m) { if(n<2) { n=2; cout<<"\n\nThe minimum value of n(exp) sould be 2"; cout<<"\n\nDefault value is initialized to n: "<<n; } while(i<=n) { calc=calc*m; i++;

} return calc; } void display() { cout<<"\nResults: "<<calc; } }; void main() { clrscr(); int n; double m; cout<<"\nEnter the base: "; cin>>m; cout<<"\nEnter the exp: "; cin>>n; base_exp obj; obj.power(n, m); obj.display(); getch(); }

Ques 7: Define a class to represent a bank account. Include the following members: Data members: i). Name of the depositor ii). Account number iii). Type of account iv). Balance amount in the account Member functions: i). To assign initial values ii). To deposit an amount iii). To withdraw an amount after checking the balance iv). To display name and balance write a main program to test the program. #include<iostream.h> #include<stdio.h> #include<conio.h> class bank_acc { public: char n_dep[50], type_acc[10]; unsigned int acc_no, chk_acc_no; double balance, bal_dep, bal_witdrw; void account() { cout<<"\nEnter the Name of Customers: "; gets(n_dep); cout<<"\nEnter the type of a/c (e.g. saving, current): "; gets(type_acc); cout<<"\nEnter the a/c number upto 5 digits or 16 digits: "; cin>>acc_no; cout<<"\nEnter the Balance in that a/c: "; cin>>balance; cout<<"\n\nAccount created Successfully ;-) !!!"; getch(); } void deposit() { cout<<"\nEnter the a/c number to deposit money: "; cin>>chk_acc_no;

if(chk_acc_no==acc_no) { cout<<"\nAccout is valid!!! ;->"; cout<<"\n\nEnter the total amount to deposit money: "; cin>>bal_dep; balance=bal_dep+balance; cout<<"\nAmount deposited succcessfully\n"; cout<<"\nTotal balance= "<<balance; } else { cout<<"\n\n\tAccount Invalid :-( pleaze retry\n"; } } void withdrw() { cout<<"\n\nEnter the a/c number to withdrw money: "; cin>>chk_acc_no; if(chk_acc_no==acc_no) { cout<<"\nAccout is valid!!! ;->"; cout<<"\n\nBalance in a/c: "<<balance; cout<<"\nEnter the total amount to Withdraw money: "; cin>>bal_witdrw; if(bal_witdrw<=balance) { balance-=bal_witdrw; cout<<"\nBalance debited\n"; cout<<"\nTotal amount= "<<balance; } else cout<<"\nTransaction cannot be processed!!! Insufficient Fund ;(\n"; } else { cout<<"\nAccount Invalid :-( pleaze retry\n"; } } void details() {

cout<<"\n\n\tName of Depositor\tBalance\t\tType of a/c:\n"; cout<<"\t"<<n_dep<<"\t\t\t"<<balance<<"\t\t"<<type_acc<<"\n\n"; } }; void main() { clrscr(); cout<<"\n\nPlease fill up the initial form:\n"; bank_acc obj; obj.account(); int n; char ch; do { clrscr(); cout<<"\n1. Deposit amount"; cout<<"\n2. Withdraw amount"; cout<<"\n3. Detail of a/c"; cout<<"\n\nEnter your choice\n"; cin>>n; switch(n) { case 1: obj.deposit(); break; case 2: obj.withdrw(); break; case 3: obj.details(); break; default: cout<<"\nWrong choice !!! ;-(\n"; } cout<<"\nDo you wish to continue (y/n): "; cin>>ch; }while(ch=='y' || ch=='Y'); getch(); }

Ques 8: Create two classes DM and DB which store the value of distances. DM stores distances in metres and centimetres and DB in feet and inches. Write a program that can read values for the class objects and add one object of DM with another object of DB. Use a friend function to carry out the addition operation. The object that stores the results may be DM object or DB object, depending on the units in which the results are required. The display should be in the format of feet and inches or meters and centimeters depending on the object on display. #include<iostream.h> #include<conio.h> class DM { public: int metre, centimetres; void read_val() { cout<<"\n\n\n\tEnter the metre: "; cin>>metre; cout<<"\n\n\n\tEnter the centimetres: "; cin>>centimetres; } void display() { cout<<"\n\n\tMetre: "<<metre; cout<<"\n\tCentimetres: "<<centimetres; } friend DM operator +(DM); }; class DB { public: int feet, inches; void read_val() { cout<<"\n\n\n\tEnter the feet: "; cin>>feet; cout<<"\n\n\n\tEnter the inches: "; cin>>inches; } };

DM operator +(DM m, DB b) { DM m1; m1.metre=m.metre + b.feet; m1.centimetres=m.centimetres + b.inches; if(m1.centimetres>99) { m1.centimetres-=100; m1.metre+=1; } return m1; } void main() { clrscr(); DM m, m1; m.read_val(); DB b; b.read_val(); m1=m+b; m1.display(); getch(); }

Ques 9: A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publishers and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and display whether it is available or not. If it is not, an appropriate message displayed. If it is, then the system displays the book details and request for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed otherwise a message Required copies not in stock is displayed. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class book_shop { public: char b_author[50], u_author[50], b_title[100], u_title[100], b_publisher[50]; int b_stock, u_require; float b_price; void b_shop() { cout<<"\n\n\t\tEnter the book_name: "; gets(b_title); cout<<"\n\t\tEnter the book_author: "; gets(b_author); cout<<"\n\t\tEnter the book_publisher: "; gets(b_publisher); cout<<"\n\t\tEnter the book_price: "; cin>>b_price; cout<<"\n\t\tEnter the stock position: "; cin>>b_stock; } void b_enquiry() { char ch; cout<<"\n\n\tBook Found...!!!"; cout<<"\n\t\tBook_Name: ";

puts(b_title); cout<<"\n\t\tBook_author: "; puts(b_author); cout<<"\n\t\tBook_publisher: "; puts(b_publisher); cout<<"\n\t\tBook_price: "<<b_price; do { cout<<"\n\n\t\tEnter the required number of book: "; cin>>u_require; if(u_require<=b_stock) { float avg; cout<<"\n\t\t\tRequired Copies not in stock!!!"; b_price=b_price*u_require; avg=b_price-(b_price*0.10f); cout<<"\n\t\t\t\tTotal cost @10% discount: "<<avg; } else { cout<<"\n\t\tRequired Copies not in stock!!!"; cout<<"\n\n\tWant to reinsert number of book requires y/n: "; cin>>ch; } }while(ch=='y'||ch=='Y'); } }; void main() { clrscr(); int n_books, i=0, flag=0; char s_title[50], s_author[50]; cout<<"\n\nEnter the number of Book in Shop: "; cin>>n_books; book_shop obj[100]; for(i=1;i<=n_books;i++) { cout<<"\n\tEnter details of "<<i<<" book:-";

obj[i].b_shop(); clrscr(); } clrscr(); cout<<"\nSearch a book...!"; cout<<"\n\n\tEnter the book_name to search: "; gets(s_title); cout<<"\n\tEnter the book_author: "; gets(s_author); for(i=1;i<=n_books;i++) { if((strcmp(s_title,obj[i].b_title)==0) || (strcmp(s_author,obj[i].b_author)==0)) { obj[i].b_enquiry(); flag=1; } } if(flag==0) cout<<"\nBook not found..!"; getch(); }

Ques 10: Improve the system designed above to incorporate the following features: a) The price of the books should be updated as and when required. Use a private member function to implement this. b) The stock value of each book should be automatically updated as soon as a transaction is completed. c) The number of successful and unsuccessful transactions should be recorded for the purpose of statistical analysis. Use static data members to keep count transactions.

#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class book_shop { int n_price; public: char b_author[50], u_author[50], b_title[100], u_title[100], b_publisher[50]; int b_stock, u_require; float b_price; static int count, count1; void b_shop() { cout<<"\n\n\t\tEnter the book_name: "; gets(b_title); cout<<"\n\t\tEnter the book_author: "; gets(b_author); cout<<"\n\t\tEnter the book_publisher: "; gets(b_publisher); cout<<"\n\t\tEnter the current book_price: "; cin>>b_price; cout<<"\n\t\tEnter the stock position: "; cin>>b_stock; count=count1=0; }

void b_enquiry() { char ch; cout<<"\n\n\tBook Found...!!!"; cout<<"\n\t\tBook_Name: "; puts(b_title); cout<<"\n\t\tBook_author: "; puts(b_author); cout<<"\n\t\tBook_publisher: "; puts(b_publisher); cout<<"\n\t\tBook_price: "<<b_price; cout<<"\n\n\t\tEnter the required number of book: "; cin>>u_require; if(u_require<=b_stock) { float avg; cout<<"\n\t\t\tRequired Copies not in stock!!!"; b_price=b_price*u_require; avg=b_price-(b_price*0.10f); cout<<"\n\t\t\t\tTotal cost @10% discount: "<<avg; count++; b_stock-=u_require; } else { cout<<"\n\t\tRequired Copies not in stock!!!"; count1++; }

} private: void up_price() { cout<<"\n\tEnter the new price: "; cin>>n_price; b_price=n_price; cout<<"\nBook price updated!!!";

} public: void update() { up_price(); } }; int book_shop ::count; int book_shop ::count1; void main() { clrscr(); int n_books, i=0, flag=0; char s_title[50], s_author[50],ch; cout<<"\n\nEnter the number of Book in Shop: "; cin>>n_books; book_shop obj[100]; for(i=1;i<=n_books;i++) { cout<<"\n\tEnter details of "<<i<<" book:-"; obj[i].b_shop(); clrscr(); } cout<<"\n\n\tWant to update the price of book: "; cin>>ch; if(ch=='y'||ch=='Y') { cout<<"\n\n\tEnter the book_name to search: "; gets(s_title); cout<<"\n\tEnter the book_author: "; gets(s_author); for(i=1;i<=n_books;i++) { if((strcmp(s_title,obj[i].b_title)==0) || (strcmp(s_author,obj[i].b_author)==0)) { obj[i].update(); } }

clrscr(); cout<<"\nSearch a book...!"; cout<<"\n\n\tEnter the book_name to search: "; gets(s_title); cout<<"\n\tEnter the book_author: "; gets(s_author); for(i=1;i<=n_books;i++) { if((strcmp(s_title,obj[i].b_title)==0) || (strcmp(s_author,obj[i].b_author)==0)) { obj[i].b_enquiry(); flag=1; } } if(flag==0) { cout<<"\nBook not found..!"; obj[i].count1++; } cout<<"\n\tSuccessfull transaction: "<<obj[i].count; cout<<"\n\tunsuccessfull transaction: "<<obj[i].count1; getch(); }

Ques 11: Create a class FLOAT that contains one float data member. Overload all the four arithmetic operators so that they operate on the objects of FLOAT. #include<iostream.h> #include<conio.h> class FLOAT { public: float num; FLOAT() {} FLOAT(float x) { num=x; } void operator +(FLOAT f2) { FLOAT f3; f3.num=num+f2.num; cout<<"\n\n\t\t\tAddition: "<<f3.num; } void operator -(FLOAT f2) { FLOAT f3; f3.num=num-f2.num; cout<<"\n\n\t\t\tSubstraction: "<<f3.num; } void operator *(FLOAT f2) { FLOAT f3; f3.num=num*f2.num; cout<<"\n\n\t\t\tMultiplication: "<<f3.num; } void operator /(FLOAT f2) { FLOAT f3; f3.num=num/f2.num; cout<<"\n\n\t\t\tDivision: "<<f3.num;

} }; void main() { clrscr(); float num1, num2; cout<<"\nEnter the 1st number: "; cin>>num1; cout<<"\nEnter the 2nd number: "; cin>>num2; FLOAT obj1(num1); FLOAT obj2(num2); obj1+obj2; obj1-obj2; obj1*obj2; obj1/obj2; getch(); }

Ques 12: Assume that a bank maintains two kinds of accounts for customers, one called as savings account and the other as current account. The savings account provides compound interest and withdrawal facilities but no cheque facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below this level a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: (a). Accept deposit from a customer and update the balance. (b). Display the balance. (c). Compute and deposit interest. (d). Permit withdrawal and update the balance. (e). Check for the minimum balance, impose penalty, necessary, and update the balance. Do not use any constructors. Use member functions to initialize the class members. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class account { public: char c_name[50], t_acc[10]; unsigned long int acc_no; double acc_bal; void cinput_details() { cout<<"\n\n\tEnter the Customer name: "; gets(c_name); cout<<"\n\tEnter the type of acc: "; gets(t_acc); cout<<"\n\tEnter the acc_number: "; cin>>acc_no; cout<<"\n\tEnter the Minimum Balance: "; cin>>acc_bal; } };

class sav_acct: public account { public: double d_bal, w_bal; double ci; void d_balance() { cout<<"\n\n\tEnter the amount to be deposit: "; cin>>d_bal; acc_bal+=d_bal; cout<<"\n\tBalance in acc: "<<acc_bal; } void c_interest() { ci=acc_bal*(1+.2f); acc_bal=ci; cout<<"\n\tCompond Interest provided @2% for 1 year: "<<acc_bal; } void w_balance() { cout<<"\n\tRemember Cheque Not allowed...!"; cout<<"\n\n\tEnter the amount to be withdraw: "; cin>>w_bal; if(w_bal<=acc_bal) { cout<<"\n\tWithdraw successful!!!"; acc_bal-=w_bal; cout<<"\n\tRemaining balance: "<<acc_bal; } else { cout<<"\n\tNot enough Balance!!!"; } } void c_details() { cout<<"\n\n\nDetails of Customer!!!"; cout<<"\n\n\tAccount Number: "<<acc_no; cout<<"\n\tName of the customer: "<<c_name; cout<<"\n\tBalance: "<<acc_bal;

} }; class cur_acct: public account { public: double d_bal, w_bal, temp_bal,c_penalty; void d_balance() { cout<<"\n\n\tEnter the amount to be deposit: "; cin>>d_bal; acc_bal+=d_bal; cout<<"\n\tBalance in acc: "<<acc_bal; } void w_balance() { cout<<"\n\tRemember Cheque allowed but not interest...!"; cout<<"\n\n\tEnter the amount to be withdraw: "; cin>>w_bal; temp_bal=10000; temp_bal+=acc_bal; if(w_bal<=temp_bal) { cout<<"\n\tWithdraw successful!!!"; acc_bal-=w_bal; cout<<"\n\tRemaining balance: "<<acc_bal; if(acc_bal<=1000) { c_penalty=acc_bal*0.2f; cout<<"\n\tPenalty charges imposed: "<<c_penalty; } } else { cout<<"\n\tWithdraw limit Exceed!!!"; } } void c_details() { cout<<"\n\n\nDetails of Customer!!!"; cout<<"\n\n\tAccount Number: "<<acc_no; cout<<"\n\tName of the customer: "<<c_name;

cout<<"\n\tBalance: "<<acc_bal; } }; void main() { int num,num1,num2; char ch,ch1,ch2; sav_acct sav; cur_acct cur; do { clrscr(); cout<<"\n\t1. Saving A/C"; cout<<"\n\t2. Current A/C"; cout<<"\n\n\t\tEnter your choice to create an a/c: "; cin>>num; switch(num) { case 1: sav.cinput_details(); do { clrscr(); cout<<"\n\n\tEnter your choice to update a/c:"; cout<<"\n\t\t1.Deposit Balance"; cout<<"\n\t\t2.Withdrw Balance"; cout<<"\n\t\t3.View Details"; cout<<"\n\t\t\tChoice: "; cin>>num2; switch(num2) { case 1:sav.d_balance(); break; case 2:sav.w_balance(); break; case 3:sav.c_details(); sav.c_interest(); break; default: cout<<"\nWrong choice!!!"; } cout<<"\nDo yout want to Continue: "; cin>>ch2; }while(ch2=='y'||ch2=='Y'); break;

case 2: cur.cinput_details(); do { clrscr(); cout<<"\n\n\tEnter your choice to update a/c:"; cout<<"\n\t\t1.Deposit Balance"; cout<<"\n\t\t2.Withdrw Balance"; cout<<"\n\t\t3.View Details"; cout<<"\n\t\t\tChoice: "; cin>>num1; switch(num1) { case 1:cur.d_balance(); break; case 2:cur.w_balance(); break; case 3:cur.c_details(); break; default: cout<<"\nWrong choice!!!"; } cout<<"\nDo yout want to Continue: "; cin>>ch1; }while(ch1=='y'||ch1=='Y'); break; default: cout<<"\n\t\t\t\tWrong Choice!!!"; } cout<<"\nDo yout want to Continue: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques 13: Modify the above program to include constructors for all the three classes. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> class account { public: char c_name[50], t_acc[10]; unsigned long int acc_no; double acc_bal; account() { strcpy(c_name,NULL); strcpy(t_acc,NULL); acc_no=acc_bal=0; } void cinput_details() { cout<<"\n\n\tEnter the Customer name: "; gets(c_name); cout<<"\n\tEnter the type of acc: "; gets(t_acc); cout<<"\n\tEnter the acc_number: "; cin>>acc_no; cout<<"\n\tEnter the Minimum Balance: "; cin>>acc_bal; } }; class sav_acct: public account { public: double d_bal, w_bal, ci; sav_acct() { d_bal=w_bal=ci=0; }

void d_balance() { cout<<"\n\n\tEnter the amount to be deposit: "; cin>>d_bal; acc_bal+=d_bal; cout<<"\n\tBalance in acc: "<<acc_bal; } void c_interest() { ci=acc_bal*(1+.2f); acc_bal=ci; cout<<"\n\tCompond Interest provided @2% for 1 year: "<<acc_bal; } void w_balance() { cout<<"\n\tRemember Cheque Not allowed...!"; cout<<"\n\n\tEnter the amount to be withdraw: "; cin>>w_bal; if(w_bal<=acc_bal) { cout<<"\n\tWithdraw successful!!!"; acc_bal-=w_bal; cout<<"\n\tRemaining balance: "<<acc_bal; } else { cout<<"\n\tNot enough Balance!!!"; } } void c_details() { cout<<"\n\n\nDetails of Customer!!!"; cout<<"\n\n\tAccount Number: "<<acc_no; cout<<"\n\tName of the customer: "<<c_name; cout<<"\n\tBalance: "<<acc_bal; } }; class cur_acct: public account { public:

double d_bal, w_bal, temp_bal,c_penalty; cur_acct() { d_bal=w_bal=temp_bal=c_penalty=0; } void d_balance() { cout<<"\n\n\tEnter the amount to be deposit: "; cin>>d_bal; acc_bal+=d_bal; cout<<"\n\tBalance in acc: "<<acc_bal; } void w_balance() { cout<<"\n\tRemember Cheque allowed but not interest...!"; cout<<"\n\n\tEnter the amount to be withdraw: "; cin>>w_bal; temp_bal=10000; temp_bal+=acc_bal; if(w_bal<=temp_bal) { cout<<"\n\tWithdraw successful!!!"; acc_bal-=w_bal; cout<<"\n\tRemaining balance: "<<acc_bal; if(acc_bal<=1000) { c_penalty=acc_bal*0.2f; cout<<"\n\tPenalty charges imposed: "<<c_penalty; } } else { cout<<"\n\tWithdraw limit Exceed!!!"; } } void c_details() { cout<<"\n\n\nDetails of Customer!!!"; cout<<"\n\n\tAccount Number: "<<acc_no; cout<<"\n\tName of the customer: "<<c_name; cout<<"\n\tBalance: "<<acc_bal;

} }; void main() { int num,num1,num2; char ch,ch1,ch2; sav_acct sav; cur_acct cur; do { clrscr(); cout<<"\n\t1. Saving A/C"; cout<<"\n\t2. Current A/C"; cout<<"\n\n\t\tEnter your choice to create an a/c: "; cin>>num; switch(num) { case 1: sav.cinput_details(); do { clrscr(); cout<<"\n\n\tEnter your choice to update a/c:"; cout<<"\n\t\t1.Deposit Balance"; cout<<"\n\t\t2.Withdrw Balance"; cout<<"\n\t\t3.View Details"; cout<<"\n\t\t\tChoice: "; cin>>num2; switch(num2) { case 1:sav.d_balance(); break; case 2:sav.w_balance(); break; case 3:sav.c_details(); sav.c_interest(); break; default: cout<<"\nWrong choice!!!"; } cout<<"\nDo yout want to Continue: "; cin>>ch2; }while(ch2=='y'||ch2=='Y'); break; case 2: cur.cinput_details();

do { clrscr(); cout<<"\n\n\tEnter your choice to update a/c:"; cout<<"\n\t\t1.Deposit Balance"; cout<<"\n\t\t2.Withdrw Balance"; cout<<"\n\t\t3.View Details"; cout<<"\n\t\t\tChoice: "; cin>>num1; switch(num1) { case 1:cur.d_balance(); break; case 2:cur.w_balance(); break; case 3:cur.c_details(); break; default: cout<<"\nWrong choice!!!"; } cout<<"\nDo yout want to Continue: "; cin>>ch1; }while(ch1=='y'||ch1=='Y'); break; default: cout<<"\n\t\t\t\tWrong Choice!!!"; } cout<<"\nDo yout want to Continue: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques 14: An educational institution wishes to maintain a database of its employees. The database is divided into a number of classes whose hierarchical relationships are shown in fig below. The figure also shows and define functions to create the database and individual information as and when required. Staff Code name Teacher Subject publication Typist speed Officer grade

regular

Casual Daily wages

#include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class staff { public: int code; char name[50]; staff() { code=0; strcpy(name,NULL); } }; class teacher: public staff { public: char subject[40]; teacher()

{ strcpy(subject,NULL); } void t_info() { cout<<"\n\n\tEnter details of Teacher...!"; cout<<"\n\n\tEnter the id code: "; cin>>code; cout<<"\n\tEnter name of employee: "; gets(name); cout<<"\n\tEnter the subject publication: "; gets(subject); } void d_info() { cout<<"\n\n\t\t\t\t\tDetails of Teacher:"; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tEmployee Code: "<<code; cout<<"\n\tSubject Publication: "; puts(subject); } }; class officer: public staff { public: char grade; officer() { grade=NULL; } void g_info() { cout<<"\n\n\tEnter details of Officer...!"; cout<<"\n\n\tEnter the id code: "; cin>>code;

cout<<"\n\tEnter name of employee: "; gets(name); cout<<"\n\tEnter the Grade for teacher: "; cin>>grade; } void d_grade() { cout<<"\n\n\t\t\t\t\tDetails of Officer:"; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tEmployee Code: "<<code; cout<<"\n\tGrade of teacher: "<<grade; } }; class typist: public staff { public: float speed; typist() { speed=0; } }; class regular: public typist { public: void s_info() { cout<<"\n\n\t\t\tEnter Details of Regualr Worker(typist)!!!"; cout<<"\n\n\tEnter the name of Employee: "; gets(name); cout<<"\n\tEnter it's code: "; cin>>code; cout<<"\n\tEnter the typing speed of regular workers: "; cin>>speed; } void d_speed() { cout<<"\n\n\t\t\t\t\tRegular Worker details(typist):"; cout<<"\n\n\tCode of Employee: "<<code; cout<<"\n\tName of Employee: ";

puts(name); cout<<"\n\tIt's typing speed: "<<speed; } }; class casual: public typist { public: float d_wages; casual() { d_wages=0; } void cs_info() { cout<<"\n\n\t\t\tEnter Details of Casual Worker(typist)!!!"; cout<<"\n\n\tEnter the name of Employee: "; gets(name); cout<<"\n\tEnter it's code: "; cin>>code; cout<<"\n\tEnter the typing speed of casual workers: "; cin>>speed; cout<<"\n\tEnter the it's daily wages: "; cin>>d_wages; } void d_cspeed() { cout<<"\n\n\t\t\t\t\tCasual Worker details(typist):"; cout<<"\n\n\tCode of Employee: "<<code; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tDaily Wages for Casual Employee: "<<d_wages; cout<<"\n\tIt's typing speed: "<<speed; } }; void main() { staff s; typist t1; teacher t; officer o;

regular r; casual c; int num; char ch; do { clrscr(); cout<<"\n\n\n\t\tChoose one to Enter details...!"; cout<<"\n\n\t 1.Teacher"; cout<<"\n\t 2.Grading Officer"; cout<<"\n\t 3.Regular(typist)"; cout<<"\n\t 4.Casual(typist)"; cout<<"\n\t 5.Details of Teacher"; cout<<"\n\t 6.Details of Officer"; cout<<"\n\t 7.Details of Regular"; cout<<"\n\t 8.Details of casual typist"; cout<<"\n\nChoice: "; cin>>num; switch(num) { case 1: t.t_info(); break; case 2: o.g_info(); break; case 3: r.s_info(); break; case 4: c.cs_info(); break; case 5: t.d_info(); break; case 6: o.d_grade(); break; case 7: r.d_speed(); break; case 8: c.d_cspeed(); break; default: cout<<"\n\tWrong Choice!!!"; } cout<<"\n\n\t\tWant to cont.....y/n: "; cin>>ch;

}while(ch=='y'||ch=='Y'); getch(); }

Ques 15: The database created above does not include educational information of the staff. It has been decided to add this information to teachers and officers (and not for typists) which will help the management in decision making with regard to training, promotion, etc. Add another data class called education that holds two pieces of educational information, namely, highest qualification in general education and highest professional qualification. The class should be inherited by the classes teacher and officer. Modify the program of Q14 to incorporate these additions. #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class staff { public: int code; char name[50]; staff() { code=0; strcpy(name,NULL); } }; class education { public: int p_qualify, g_qualify; education() { p_qualify=g_qualify=0; } }; class teacher: public staff, public education { public: char subject[40]; teacher() { strcpy(subject,NULL); } void t_info()

{ cout<<"\n\n\tEnter details of Teacher...!"; cout<<"\n\n\tEnter the id code: "; cin>>code; cout<<"\n\tEnter name of employee: "; gets(name); cout<<"\n\tEnter his/her general Qualifacation in years: "; cin>>g_qualify; cout<<"\n\tEnter his/her professional Qualifacation in years: "; cin>>p_qualify; cout<<"\n\tEnter the subject publication: "; gets(subject); } void d_info() { cout<<"\n\n\t\t\t\t\tDetails of Teacher:"; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tEmployee Code: "<<code; cout<<"\n\tHis/her general Qualifacation in years: "<<g_qualify; cout<<"\n\tHis/her professional Qualifacation in years: "<<p_qualify; cout<<"\n\tSubject Publication: "; puts(subject); } }; class officer: public staff, public education { public: char grade; officer() { grade=NULL; } void g_info()

{ cout<<"\n\n\tEnter details of Officer...!"; cout<<"\n\n\tEnter the id code: "; cin>>code; cout<<"\n\tEnter name of employee: "; gets(name); cout<<"\n\tEnter his/her general Qualifacation in years: "; cin>>g_qualify; cout<<"\n\tEnter his/her professional Qualifacation in years: "; cin>>p_qualify; cout<<"\n\tEnter the Grade for teacher: "; cin>>grade; } void d_grade() { cout<<"\n\n\t\t\t\t\tDetails of Officer:"; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tEmployee Code: "<<code; cout<<"\n\tHis/her general Qualifacation in years: "<<g_qualify; cout<<"\n\tHis/her professional Qualifacation in years: "<<p_qualify; cout<<"\n\tGrade of teacher: "<<grade; } }; class typist: public staff { public: float speed; typist() { speed=0; } }; class regular: public typist { public: void s_info()

{ cout<<"\n\n\t\t\tEnter Details of Regualr Worker(typist)!!!"; cout<<"\n\n\tEnter the name of Employee: "; gets(name); cout<<"\n\tEnter it's code: "; cin>>code; cout<<"\n\tEnter the typing speed of regular workers: "; cin>>speed; } void d_speed() { cout<<"\n\n\t\t\t\t\tRegular Worker details(typist):"; cout<<"\n\n\tCode of Employee: "<<code; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tIt's typing speed: "<<speed; } }; class casual: public typist { public: float d_wages; casual() { d_wages=0; } void cs_info() { cout<<"\n\n\t\t\tEnter Details of Casual Worker(typist)!!!"; cout<<"\n\n\tEnter the name of Employee: "; gets(name); cout<<"\n\tEnter it's code: "; cin>>code; cout<<"\n\tEnter the typing speed of casual workers: "; cin>>speed; cout<<"\n\tEnter the it's daily wages: "; cin>>d_wages; } void d_cspeed() { cout<<"\n\n\t\t\t\t\tCasual Worker details(typist):";

cout<<"\n\n\tCode of Employee: "<<code; cout<<"\n\tName of Employee: "; puts(name); cout<<"\n\tDaily Wages for Casual Employee: "<<d_wages; cout<<"\n\tIt's typing speed: "<<speed; } }; void main() { staff s; education e; typist t1; teacher t; officer o; regular r; casual c; int num; char ch; do { clrscr(); cout<<"\n\n\n\t\tChoose one to Enter details...!"; cout<<"\n\n\t 1.Teacher"; cout<<"\n\t 2.Grading Officer"; cout<<"\n\t 3.Regular(typist)"; cout<<"\n\t 4.Casual(typist)"; cout<<"\n\t 5.Details of Teacher"; cout<<"\n\t 6.Details of Officer"; cout<<"\n\t 7.Details of Regular"; cout<<"\n\t 8.Details of casual typist"; cout<<"\n\nChoice: "; cin>>num; switch(num) { case 1: t.t_info(); break; case 2: o.g_info(); break; case 3: r.s_info(); break; case 4: c.cs_info();

break; case 5: t.d_info(); break; case 6: o.d_grade(); break; case 7: r.d_speed(); break; case 8: c.d_cspeed(); break; default: cout<<"\n\tWrong Choice!!!"; } cout<<"\n\n\t\tWant to cont.....y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques 16: Consider a class network of figure below. The class master derives information from both account and admin classes which in turn derive information from the class person. Define all the four classes and write a program to create, update and display the information contained in master objects. Person Name Code Admin experience

Account Pay

Master Name Code Experience pay

#include<iostream.h> #include<conio.h> class Person { public: char name[50]; int code; void inf() { cout<<"\n\nEnter the Name of Person class: "; cin>>name; cout<<"\n\nEnter its code: "; cin>>code; } }; class Account: public virtual Person { public: int pay; void inf1() {

cout<<"\n\nEnter the pay in Account class: "; cin>>pay; } }; class Admin: public virtual Person { public: int experience; void inf2() { cout<<"\n\nEnter the experience of admin class in years: "; cin>>experience; } }; class Master: public Account,public Admin { public: void create() { inf(); inf1(); inf2(); } void display() { cout<<"\n\nName:\t"<<name; cout<<"\n\nCode:\t"<<code; cout<<"\n\nPay:\t"<<pay; cout<<"\n\nExperience: "<<experience; } }; void main() { clrscr(); int n; char ch; Master obj; obj.create(); cout<<"\n\nDo you want to update any Information!!!"; cout<<"\n\nIf yes press 'Y' else press 'N' to view details: ";

cin>>ch; if(ch=='y'||ch=='Y') { do { cout<<"\n\nEnter the choice you want to update information:-"; cout<<"\n1.Name"; cout<<"\n2.ID_Code"; cout<<"\n3.Amt Pay"; cout<<"\n4.Experience\n"; cin>>n; switch(n) { case 1: cout<<"\n\nPlease enter the name: "; cin>>obj.name; break; case 2: cout<<"\n\nPlease enter ID code: "; cin>>obj.code; break; case 3: cout<<"\n\nPlease enter Amt pay: "; cin>>obj.pay; break; case 4: cout<<"\n\nPlease enter it's experience: "; cin>>obj.experience; break; default: cout<<"\n\nSorry Wrong choice ;-< !!!"; } cout<<"\n\nWant to update the information (y/n): "; cin>>ch; }while(ch=='y'||ch=='Y'); } else { cout<<"\nThanks!!! ;->"; } obj.display(); getch(); }

Ques 17: In Q14, the classes teacher, officer and typist are derived from the class staff. As we know, we can use container classes in place of inheritance in some situations. Redesign the program of Q14 such that the classes teacher, officer, and typist contain the objects of staff. #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class staff { public: int code; char name[50]; staff() { code=0; strcpy(name,NULL); } friend class teacher; friend class officer; friend class typist; }; class teacher { public: char subject[40]; staff st; teacher() { strcpy(subject,NULL); } void t_info() { cout<<"\n\n\tEnter details of Teacher...!"; cout<<"\n\n\tEnter the id code: "; cin>>st.code; cout<<"\n\tEnter name of employee: "; gets(st.name);

cout<<"\n\tEnter the subject publication: "; gets(subject); } void d_info() { cout<<"\n\n\t\t\t\t\tDetails of Teacher:"; cout<<"\n\tName of Employee: "; puts(st.name); cout<<"\n\tEmployee Code: "<<st.code; cout<<"\n\tSubject Publication: "; puts(subject); } }; class officer { public: char grade; staff st; officer() { grade=NULL; } void g_info() { cout<<"\n\n\tEnter details of Officer...!"; cout<<"\n\n\tEnter the id code: "; cin>>st.code; cout<<"\n\tEnter name of employee: "; gets(st.name); cout<<"\n\tEnter the Grade for teacher: "; cin>>grade; } void d_grade() { cout<<"\n\n\t\t\t\t\tDetails of Officer:"; cout<<"\n\tName of Employee: "; puts(st.name);

cout<<"\n\tEmployee Code: "<<st.code; cout<<"\n\tGrade of teacher: "<<grade; } }; class typist { public: float speed; staff st; typist() { speed=0; } }; class regular: public typist { public: void s_info() { cout<<"\n\n\t\t\tEnter Details of Regualr Worker(typist)!!!"; cout<<"\n\n\tEnter the name of Employee: "; gets(st.name); cout<<"\n\tEnter it's code: "; cin>>st.code; cout<<"\n\tEnter the typing speed of regular workers: "; cin>>speed; } void d_speed() { cout<<"\n\n\t\t\t\t\tRegular Worker details(typist):"; cout<<"\n\n\tCode of Employee: "<<st.code; cout<<"\n\tName of Employee: "; puts(st.name); cout<<"\n\tIt's typing speed: "<<speed; } }; class casual: public typist { public: float d_wages;

casual() { d_wages=0; } void cs_info() { cout<<"\n\n\t\t\tEnter Details of Casual Worker(typist)!!!"; cout<<"\n\n\tEnter the name of Employee: "; gets(st.name); cout<<"\n\tEnter it's code: "; cin>>st.code; cout<<"\n\tEnter the typing speed of casual workers: "; cin>>speed; cout<<"\n\tEnter the it's daily wages: "; cin>>d_wages; } void d_cspeed() { cout<<"\n\n\t\t\t\t\tCasual Worker details(typist):"; cout<<"\n\n\tCode of Employee: "<<st.code; cout<<"\n\tName of Employee: "; puts(st.name); cout<<"\n\tDaily Wages for Casual Employee: "<<d_wages; cout<<"\n\tIt's typing speed: "<<speed; } }; void main() { staff s; typist t1; teacher t; officer o; regular r; casual c; int num; char ch; do { clrscr();

cout<<"\n\n\n\t\tChoose one to Enter details...!"; cout<<"\n\n\t 1.Teacher"; cout<<"\n\t 2.Grading Officer"; cout<<"\n\t 3.Regular(typist)"; cout<<"\n\t 4.Casual(typist)"; cout<<"\n\t 5.Details of Teacher 'n' Officer"; cout<<"\n\t 6.Details of Regular 'n' casual typist"; cout<<"\n\nChoice: "; cin>>num; switch(num) { case 1: t.t_info(); break; case 2: o.g_info(); break; case 3: r.s_info(); break; case 4: c.cs_info(); break; case 5: t.d_info(); o.d_grade(); break; case 6: r.d_speed(); c.d_cspeed(); break; default: cout<<"\n\tWrong Choice!!!"; } cout<<"\n\n\t\tWant to cont.....y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques 18: (a) Create a base class called shape. Use this class to store two double type values that could be used to compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add to the base class, a member function get_data() to initialize base class data members and another member function display_area() to compute and display the area of figures. Make display_area() as a virtual function and redefine this function in the derived classes to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively, and display the area. Remembered the two values given as input will be treated as lengths of two sides in the case of rectangles, and as base and height in the case of triangles, and used as follows: Area of rectangle=x*y; Area of triangle= 1/2*x*y; #include<iostream.h> #include<process.h> #include<conio.h> class shape { public: double x, y; void get_data() { cout<<"\n\tEnter the first side: "; cin>>x; cout<<"\n\tEnter the second side: "; cin>>y; } virtual void display_area() { cout<<"\n\n\t\t\tArea of Shape...!"; } }; class triangle: public shape { public: double t_area; void display_area() { t_area=(0.5f)*(x*y);

cout<<"\n\tTriangle: "<<t_area; } }; class rectangle: public shape { public: double r_area; void display_area() { r_area=x*y; cout<<"\n\tRectangle: "<<r_area; } }; void main() { shape *ptr,s; triangle t; rectangle r; int num; char ch; do { clrscr(); cout<<"\n\n\t\t\tArea of Shape...!"; cout<<"\n\n\t1. Triangle"; cout<<"\n\n\t2. Rectangle"; cout<<"\n\n\t3. Exit"; cout<<"\n\n\n\t\tChoice: "; cin>>num; switch(num) { case 1: ptr=&s; cout<<"\n\t\tEnter the Base 'n' Height of triangle...!"; t.get_data(); ptr->display_area(); ptr=&t; break; case 2: ptr=&s; cout<<"\n\t\tEnter the Length 'n' Breadth of rectangle...!"; r.get_data();

ptr->display_area(); ptr=&r; break;

case 3: exit(0); default:cout<<"\nWrong Choice !!!"; } ptr->display_area(); cout<<"\n\n\tWant to continue y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques18: (b) Extend the above program to display the area of circle. This requires addition of a new derived class circle that computes the area of a circle. Remember, for a circle we need only one value, its radius, but the get_data() function in the base class requires two values to be passed. #include<iostream.h> #include<process.h> #include<conio.h> #define pi 3.14 class shape { public: double x, y; void get_data(double s1, double s2) { x=s1; y=s2; /*cout<<"\n\tEnter the first side: "; cin>>x; cout<<"\n\tEnter the second side: "; cin>>y;*/ } virtual void display_area() { cout<<"\n\n\t\t\tArea of Shape...!"; } }; class triangle: public shape { public: double t_area; void display_area() { t_area=(0.5f)*(x*y); cout<<"\n\tTriangle: "<<t_area; } }; class rectangle: public shape { public: double r_area;

void display_area() { r_area=x*y; cout<<"\n\tRectangle: "<<r_area; } }; class circle: public shape { public: double c_area; void display_area() { c_area=pi*x*y; cout<<"\n\tCircle: "<<c_area; } }; void main() { shape *ptr,s; triangle t; rectangle r; circle c; int num; char ch; do { clrscr(); cout<<"\n\n\t\t\tArea of Shape...!"; cout<<"\n\t1. Triangle"; cout<<"\n\t2. Rectangle"; cout<<"\n\t3. Circle"; cout<<"\n\t3. Exit"; cout<<"\n\n\t\tChoice: "; cin>>num; switch(num) { case 1: ptr=&s; cout<<"\n\tEnter the Base 'n' Height of triangle...!"; cout<<"\n\n\t\tBase: "; cin>>t.x;

cout<<"\n\t\tHeight: "; cin>>t.y; t.get_data(t.x,t.y); ptr->display_area(); ptr=&t; break; case 2: ptr=&s; cout<<"\n\t\tEnter the Length 'n' Breadth of rectangle...!"; cout<<"\n\n\t\tLength: "; cin>>r.x; cout<<"\n\t\tBreadth: "; cin>>r.y; r.get_data(r.x,r.y); ptr->display_area(); ptr=&r; break; case 3: ptr=&s; cout<<"\n\t\tEnter the Radius of circle...!"; cout<<"\n\n\t\tRadius: "; cin>>c.x; c.y=c.x; c.get_data(c.x,c.y); ptr->display_area(); ptr=&c; break; case 4: exit(0); default:cout<<"\nWrong Choice !!!"; } ptr->display_area(); cout<<"\n\n\tWant to continue y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques 19: Develop an object oriented program in c++ for shopping list including following information: (a). Add an Item (b). Display total value (c). Delete an item (d). Display all items #include<iostream.h> #include<process.h> #include<iomanip.h> #include<malloc.h> #include<conio.h> #include<string.h> #include<stdio.h> class shop_list { char item[50]; float i_price; shop_list *next; friend void ad_item(); friend void del_item(); friend void dis_item(); }; typedef shop_list node; node *head=NULL; float value=0; void ad_item() { node *n, *temp; char a_item[50]; float a_price; cout<<"\n\n\tEnter the item: "; gets(a_item); cout<<"\n\tEnter it's estimate value: "; cin>>a_price; temp=(node *)malloc(sizeof(node)); strcpy(temp->item,a_item); temp->i_price=a_price; temp->next=NULL; value+=temp->i_price;

if(head==NULL) { head=temp; } else { n=head; while(n->next!=NULL) { n=n->next; } n->next=temp; } } void del_item() { node *n=head; char d_item[50]; cout<<"\n\n\tEnter the item to delete: "; gets(d_item); if(head==NULL) { cout<<"\n\n\tNo item is stored...!"; } else { if(strcmp(n->item,d_item)==0) { cout<<"\n\tItem deleted: "<<n->item; value-=n->i_price; n=n->next; head=n; } else { while(strcmp(n->next->item,d_item)!=0) { n=n->next; if(n==NULL) break; } if(strcmp(n->next->item,d_item)==0)

{ cout<<"\n\tItem deleted: "<<n->next->item; value-=n->next->i_price; n->next=n->next->next; } else { if(n==NULL) cout<<"\n\tItem not found...!"; } } } } void dis_item() { node *n=head; int i=1; cout<<"\n\t\t\tShopping List...!\n\n"; while(n!=NULL) { cout<<"\n\t "<<i<<". "<<n->item; cout<<"\t\t\t\t"<<setw(15)<<n->i_price; i++; n=n->next; } cout<<"\n\n\n\t\t\tTotal Value:\t"<<setw(15)<<value; } void main() { int num; char ch; do { clrscr(); cout<<"\n\n\n\t\tChoose an option...!"; cout<<"\n\n\t 1.Add item"; cout<<"\n\t 2.Delete item"; cout<<"\n\t 3.Display item"; cout<<"\n\t 4.Exit"; cout<<"\n\nChoice: "; cin>>num;

switch(num) { case 1: ad_item(); break; case 2: del_item(); break; case 3: dis_item(); break; case 4: exit(0); break; default: cout<<"\n\tWrong Choice!!!"; } cout<<"\n\n\t\tWant to cont.....y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

Ques 20: Develop an object oriented program in c++ to create a database of the following items: (a). Name of the patient (b). Age (c). Ward Number (d). Nature of illness (e). Nature of medicines (f). Date of admission The hospital charges the following rates: For first 10 days Rs. 100 per day For next 10 days Rs. 200 per day For next 10 days Rs. 300 per day Beyond 10 days Rs. 500 per day (g). Total charges #include<iostream.h> #include<malloc.h> #include<process.h> #include<conio.h> #include<string.h> #include<stdio.h> class hospital { public: char n_patient[50], ill_nature[50], n_medicine[50]; int p_age, ward_no, date, month, year, charge, n_admit; hospital *next; }; typedef hospital node; node *head=NULL; void p_entry() { char patient[50], il_nature[50], r_medicine[50],ch; int age, w_no=0, dd, mm, yy, d_admit; int charge, charge1, charge2, charge3; unsigned total; node *n, *temp; cout<<"\n\n\t\t\tGHOST HOSPITAL...!"; cout<<"\n\n\n\tEnter the Name of patient: "; gets(patient); cout<<"\n\tEnter his/her Age: ";

cin>>age; cout<<"\n\tNature of illness: "; gets(il_nature); cout<<"\n\tMedicines Requires: "; gets(r_medicine); cout<<"\n\tDate: ";cin>>dd; cout<<"\n\tMonth: ";cin>>mm; cout<<"\n\tYear: ";cin>>yy; temp=(node *)malloc(sizeof(node)); strcpy(temp->n_patient,patient); temp->p_age=age; strcpy(temp->ill_nature,il_nature); strcpy(temp->n_medicine,r_medicine); temp->date=dd; temp->month=mm; temp->year=yy; temp->next=NULL; n=head; cout<<"\n\tEnter the ward number: "; cin>>w_no; if(head==NULL) temp->ward_no=w_no; else { do { while(n->ward_no!=w_no) { n=n->next; if(n==NULL) { temp->ward_no=w_no; break; } } if(n->ward_no==w_no) { cout<<"\n\tWard acquired please re-enter the ward number: "; cin>>w_no; temp->ward_no=w_no;

} }while(n->ward_no==w_no); }

cout<<"\n\tEnter the number of date to be admit: "; cin>>d_admit; temp->n_admit=d_admit; if(d_admit<=10) { charge=100*d_admit; cout<<"\n\tFor 1-10 days charge(rs: 100 p/d): "<<charge; cout<<"\n\tTotal Charges: "<<charge; temp->charge=charge; } else if(d_admit>10 && d_admit<=20) { charge=10*100; cout<<"\n\tFor 1-10 days charge(rs: 100 p/d): "<<charge; d_admit-=10; charge1=200*d_admit; cout<<"\n\tFor 11-20 days charge(rs: 200 p/d): "<<charge1; total=charge+charge1; cout<<"\n\tTotal Charges: "<<total; temp->charge=total; } else if(d_admit>20 && d_admit<=30) { charge=10*100; cout<<"\n\tFor 1-10 days charge(rs: 100 p/d): "<<charge; d_admit-=10; charge1=200*20; cout<<"\n\tFor 11-20 days charge(rs: 200 p/d): "<<charge1; d_admit-=10; charge2=300*d_admit; cout<<"\n\tFor 21-30 days charge(rs: 300 p/d): "<<charge2; total=charge+charge1+charge2; cout<<"\n\tTotal Charges: "<<total; temp->charge=total; } else

{ charge=10*100; cout<<"\n\tFor 1-10 days charge(rs: 100 p/d): "<<charge; d_admit-=10; charge1=200*20; cout<<"\n\tFor 11-20 days charge(rs: 200 p/d): "<<charge1; d_admit-=10; charge2=300*30; cout<<"\n\tFor 21-30 days charge(rs: 300 p/d): "<<charge2; d_admit-=10; charge3=300*d_admit; cout<<"\n\tFor 31-N days charge(rs: 500 p/d): "<<charge3; total=charge+charge1+charge2+charge3; cout<<"\n\tTotal Charges: "<<total; temp->charge=total; } if(head==NULL) head=temp; else { n=head; while(n->next!=NULL) { n=n->next; } n->next=temp; } } void p_exit() { node *n=head; int w_no; cout<<"\n\tEnter the ward number to empty it: "; cin>>w_no; if(head==NULL) cout<<"\n\tNo entry is created"; else

{ if(w_no==n->ward_no) { cout<<"\n\tWard Emptied: "<<n->ward_no; n=n->next; head=n; } else { while(n->next->ward_no!=w_no) { n=n->next; if(n==NULL) break; } if(n->next->ward_no==w_no) { cout<<"\n\tWard Emptied: "<<n->next->ward_no; n->next=n->next->next; } else { if(n==NULL) cout<<"\n\tWard number not found...!"; } } } } void p_details() { node *n=head; char s_patient[50]; int w_no; cout<<"\n\tEnter the patient name: "; gets(s_patient); cout<<"\n\tEnter the ward number: "; cin>>w_no;

if(head==NULL) cout<<"\n\tNo entry is created";

else { if(strcmp(s_patient,n->n_patient)==0 && n->ward_no==w_no) { cout<<"\n\t\t\tGHOST HOSPITAL...!"; cout<<"\n\n\n\tPatient Found...!"; cout<<"\n\n\tName of patient: "; puts(n->n_patient); cout<<"\n\tHis/her Age: "<<n->p_age; cout<<"\n\tNature of illness: "; puts(n->ill_nature); cout<<"\n\tMedicine Needed: "; puts(n->n_medicine); cout<<"\n\tWard Number: "<<n->ward_no; cout<<"\n\tCharges apply for "<<n->n_admit<<" days: "<<n->charge; cout<<"\n\tDate of Admission: "<<n->date<<"/"<<n->month<<"/"<<n>year; } else { while(strcmp(s_patient,n->n_patient)!=0 || n->ward_no!=w_no) { n=n->next; if(n==NULL) break; } if(strcmp(s_patient,n->n_patient)==0 && n->ward_no==w_no) { cout<<"\n\t\t\tGHOST HOSPITAL...!"; cout<<"\n\n\n\tPatient Found...!"; cout<<"\n\n\tName of patient: "; puts(n->n_patient); cout<<"\n\tHis/her Age: "<<n->p_age; cout<<"\n\tNature of illness: "; puts(n->ill_nature);

cout<<"\n\tMedicine Needed: "; puts(n->n_medicine); cout<<"\n\tWard Number: "<<n->ward_no; cout<<"\n\tCharges apply for "<<n->n_admit<<" days: "<<n>charge; cout<<"\n\tDate of Admission: "<<n->date<<"/"<<n>month<<"/"<<n->year; } else { if(n==NULL) cout<<"\n\tPatient not Found...!"; } } } } void s_patient() { node *n=head; char n_patient[50]; int w_no,flag=0; cout<<"\n\tEnter the patient name: "; gets(n_patient); cout<<"\n\tEnter the ward number: "; cin>>w_no; while(n!=NULL) { if((strcmp(n_patient,n->n_patient)==0) || n->ward_no==w_no) { cout<<"\n\t\t\tPatient Match Found..!"; cout<<"\n\n\tName of patient: "; puts(n->n_patient); cout<<"\n\tWard Number: "<<n->ward_no; flag=1; } n=n->next; } if(flag==0) cout<<"\n\tNo match Found...!";

void main() { int num; char ch; do { clrscr(); cout<<"\n\n\n\tChoose an option...!"; cout<<"\n\n\t 1.Patient Entry details"; cout<<"\n\t 2.Patient Exit"; cout<<"\n\t 3.Details of Patient"; cout<<"\n\t 4.Search Patient"; cout<<"\n\t 5.Exit"; cout<<"\n\nChoice: "; cin>>num; switch(num) { case 1: p_entry(); break; case 2: p_exit(); break; case 3: p_details(); break; case 4: s_patient(); break; case 5: exit(0); default: cout<<"\n\tWrong Choice!!!"; } cout<<"\n\n\t\tWant to cont.....y/n: "; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }

You might also like