You are on page 1of 21

Class and Objects -Que 7.

WAP to represent the bank account with following specification


with private members: name of the depositor, account number, type of account and balance amount in the
account. The public member functions: to assign initial values, deposit amount, withdraw amount
after checking balance, and display name and balance.

#include<iostream>

using namespace std;

class BANK_539

private:

int accno_539;

string holdername_ 539;

float balance_539;

string acctype_539;

public:

void assignValues_539()

cout<<"\nEnter Name of Account

Holder :"; cin>>holdername_539;

cout<<"\nEnter Account number :";

cin>>accno_539;

cout<<"\nEnter Account Type :";

cin>>acctype_539;

cout<<"\nEnter Account balance :";

cin>>balance_539;

void withdraw_539()
{

float take_539;

cout<<"\nHolder's Account balance is :"<<balance_539;

cout<<"\nEnter amount to be withdrawn";

cin>>take_539;

balance_539=balance_539-take_539;

void deposit_539(){

float give_539;

cout<<"\nHolder's Account balance_539 is :"<<balance_539;

cout<<"\nEnter amount to be deposited :";

cin>>give_539;

balance_539=balance_539+give_539;

void DISPLAY_539()

cout<<"\nAccount Holder's Name :"<<holdername_539;

cout<<"\nHolder's Account balance

is :"<<balance_539; }

};

int main()

BANK_539 B;

B.assignValues_539();

B.withdraw_539();

B.deposit_539();
B.DISPLAY_539();

return 0;

OUTPUT:
Constructors and Destructors Que 8-A book shop maintains the inventory of
books that are being sold at the workshop. The list includes details such as author, title,
price, publisher and stock position. Whenever a customer wants a book, the sales person
inputs the title and author and the system searches the list and displays whether it is
available or not. If it is not, an appropriate message is displayed. If it is, then the system
displays the book details and requests for the number of copies required. If the
requested copies are available, the total cost of the requested copies is displayed
otherwise the message “Required copies not in stock” is displayed. WAP using a class
called Books with suitable member functions and constructors.

#include<iostream>

#include<string.h>

using namespace std;

class books_539

private:

char *title_539, *author_539, *publisher_539;

float price_539;

int stock_539;

public:
void getdata_539();

void display_539();

int search_539(char *,char *);

void buy_539();

books_539();

};

books_539::books_539()

title_539=new char[50];

author_539=new char[50];

publisher_539=new char[10];

price_539=0;
stock_539=0;

void books_539::getdata_539()

cin.ignore();

cout<<"\nEnter Author Name: ";

cin.getline(author_539,50);

cout<<"\nEnter Title: ";

cin.getline(title_539,50);

cout<<"\nEnter publisher: ";

cin.getline(publisher_539,10);

cout<<"\nEnter price: ";


cin>>price_539;

cout<<"\nEnter stock: ";

cin>>stock_539;

void books_539::display_539()

cout<<"\nAuthor Name: "<<author_539;

cout<<"\nTitle Name: "<<title_539;

cout<<"\nPublisher Name: "<<publisher_539;

cout<<"\nPrice: "<<price_539;

cout<<"\nStock available: "<<stock_539<<endl;


}

int books_539::search_539(char *title1,char *author1)

if(strcmp(title_539,title1)==0 && strcmp(author_539,author1)==0)

return 1;

else

return 0;

void books_539::buy_539()

int no_of_copies_539;
cout<<"\nEnter no. of copies required:";

cin>>no_of_copies_539;

if(no_of_copies_539<= stock_539)

cout<<"Number of entered copies is available"<<endl;

cout<<"\nPrice of "<< no_of_copies_539<<" books is :


RS."<<no_of_copies_539*price_539;

cout<<"\nThank you .... Visit again....";

else

cout<<"\nRequired copies are not available..." ;

cout<<"\nSorry for inconvinience...";


cout<<"\nThank you .... Visit again....";

int main()

int val=0;

int ch;

int n;

char a;

cout<<"\nEnter no. of books :";

cin>>n;
cout<<"\n";

books_539 b[n];

char title1[50],author1[50];

for(int i=0;i<n;i++)

cout<<"Enter details of book"<<i+1;

b[i].getdata_539();

cin.ignore();

do
{

cout<<"**MENU*\n";

cout<<"1.Display Data\n2.Search a Book\n3.Buy a Book"<<endl;

cout<<"Enter your choice:";

cin>>ch;

switch(ch)

case 1:

for(int i=0;i<n;i++)

cout<<"---------------------------------\n";

cout<<"Details of book "<<i+1<<" is ";

b[i].display_539();
}

break;

case 2:cin.ignore();

cout<<"\nEnter following details to search a book";

cout<<"\nEnter Author Name: ";

cin.getline(author1,50);

cout<<"\nEnter Title: ";

cin.getline(title1,50);

for(int i=0;i<n;i++)

val=b[i].search_539(title1,author1);
if(val==1)

cout<<"\nBook is found";

if(val==0)

cout<<"\nBook is not available\n";

return 0;

break;

case 3:cin.ignore();

cout<<"\nEnter following details to search whether the book


is available";

cout<<"\nEnter Author Name: ";


cin.getline(author1,50);

cout<<"\nEnter Title: ";

cin.getline(title1,50);

for(int i=0;i<n;i++)

val=b[i].search_539(title1,author1);

if(val==1)

cout<<"\nBook is found";

b[i].buy_539();

}
}

if(val==0)

cout<<"\nBook is not available";

return 0;

break;

cout<<"Do you want to continue:(Yes-y or No-n)"<<endl;

cin>>a;

}while(a=='y' || a=='Y');

return 0;

}
Miscellanious Que 15-A ball is thrown up in the air. Its height above the
ground is given by the formula h = 3 + 10t – t2 where t is the time in seconds
after it is thrown. For example, at Time t = 0, h = 3 + 0 - 0 = 3 Time t = 2, h =
3
+ 20 – 4 = 19 When the ball hits the ground, h becomes negative. WAP to
print out the height, h, once every second, starting a t = 0, and continuing
until h becomes negative (meaning the ball has hit the ground). (Do not print
the negative value.)

->#include <bits/stdc++.h>

#include <math.h>

using namespace std;

void Height_539(int Time_539,int Height_539)

while (Height_539

>=0) {
Time_539++;

cout << "At ->" << Time_539 << " second the Height is ->" << Height_539 <<
" units" << endl;
Height_539 = 3 + (10 * Time_539) - (Time_539 * Time_539);

int main()

int StartTime_539=0; //start at time 0

int InitialHeight_539=3;//the initial value for h when t

is 0 Height_539(StartTime_539, InitialHeight_539);
return 0;

Output:

You might also like