100% found this document useful (1 vote)
8K views4 pages

1) Write A C++ Program To Declare A Class "Book" Having Data Members Book - Name, Author and

The document contains code for two C++ programs. The first program declares a Book class with data members for book name, price, and number of pages. It gets data for two books and displays the book with the highest price. The second program declares a Staff class with data members for name and basic salary. It calculates gross salary by adding DA of 74.5% of basic salary and HRA of 30% of basic salary to the basic salary. It gets and displays the gross salary for one staff member.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
8K views4 pages

1) Write A C++ Program To Declare A Class "Book" Having Data Members Book - Name, Author and

The document contains code for two C++ programs. The first program declares a Book class with data members for book name, price, and number of pages. It gets data for two books and displays the book with the highest price. The second program declares a Staff class with data members for name and basic salary. It calculates gross salary by adding DA of 74.5% of basic salary and HRA of 30% of basic salary to the basic salary. It gets and displays the gross salary for one staff member.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

//Exercise

//1) Write a C++ program to declare a class “Book” having


data members book_name, author and
price. Accept and display data for book having maximum price.
#include<iostream.h>
#include<conio.h>
#include<string.h>
Class Book
{
Int no_of_pages;
Char book_name[50];
Public:
Float price;
Void getdata()
{
Cout<<”Enter Book name:-> “; Cin>>book_name; Cout<<”Enter Book Price:->”;
Cin>>price;

Cout<<”Enter No of pages:-> “;
Cin>>no_of_pages;
}
Void display()
{
Cout<<”\nBook name:-> “<<book_name; Cout<<”\nBook Price:->”<<price;
Cout<<”\nNo of pages:-> “<<no_of_pages;

}
};
Void main()
{
Book b1,b2;

Clrscr();
B1.getdata();
B2.getdata(); If(b1.price>b2.price)
B1.display();
Else
B2.display();
Getch();
}
OUTPUT
//2) Write a C++ program to declare a class “staff having data
members name. basic salary, DA, HRA
and calculate gross salary. Accept and display data for one staff.
// a. Where DA-74.5% of basic
// i.HRA 30% of basic.
// ii. Gross_salary-basic+HRA+DA

#include<iostream.h>
#include<conio.h>
Class staff
{
Float basic,gross_sal;
Public:
Void accept()
Cout<<”Enter Basic Salary of Staff: “;
Cin>>basic;
}
Float display ();
};
Float staff :: display()
{
Float DA=74.5, HRA=30;
Gross_sal=(basic*DA/100)+(basic*HRA/100)+basic; Return(gross_sal);

}
Void main()
{
Clrscr(); Staff s1; S1.accept();
Cout<<”Gross Salary of Employee “<<s1.display();
Getch();
}
OUTPUT:
Enter Basic Salary of Staff: 30000
Gross Salary of Employee 61350
[Program finished]

You might also like