c++ program price of a book using class and object

/*To define a class book
private
book no.-int
price-float
booktitle-char
no. of copies
getdata
display
*/
#include<iostream>
using namespace std;
class Book{
int Book_num,Quantity_Book;
char Book_Title[20];
float price;

public:
void Input();
float Total_Cost()
{
float cost=Quantity_Book * price;
return cost;
}
void Display();
};
void Book::Input(){
cout<<"Number of books ";
cin>>Book_num;
cout<<"Title of the Book ";
cin>>Book_Title;
cout<<"Quantity of Book ";
cin>>Quantity_Book;
cout<<"Enter the Price of Book ";
cin>>price;
}
void Book::Display(){
cout<<"Numbers of Books "<<Book_num<<endl;
cout<<"Title of Book "<<Book_Title<<endl;
cout<<"Quantity of Book "<<Quantity_Book<<endl;
cout<<"Total cost is "<<Total_Cost();
}
int main(){
Book b;
b.Input();
b.Display();
}



OUT-
Number of books 2
Title of the Book bum
Quantity of Book 3
Enter the Price of Book 200.80
Numbers of Books 2
Title of Book bum
Quantity of Book 3
Total cost is 602.4


Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation