In: Computer Science
C++
Write a definition for a structure type for records for books. The record contains ISBN number, price, and book cover (use H for Hard cover and P for paper cover). Part of the problem is appropriate choices of type and member names. Then declare two variables of the structure.
Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.
Used, long long int for ISBN, double for price and char for Book Cover Type.
C++ program:
#include<iostream>
using namespace std;
//structure definition for Book
struct Book{
//long long int data type for ISBN
long long int ISBN;
double price;
char BookCover;
};
//function to get data from user
void getData(struct Book &b){
cout<<"\nEnter the details of book: "<<endl;
cout<<"ISBN: ";
cin>>b.ISBN;
cout<<"Price: ";
cin>>b.price;
cout<<"Book Cover Type( H for Hard cover and P for Paper cover): ";
cin>>b.BookCover;
}
//print data stored in a structure
void printData(struct Book b){
cout<<"\n\nBook Details\n"<<endl;
cout<<"ISBN: "<<b.ISBN<<endl;
cout<<"Price: "<<b.price<<endl;
cout<<"Book Cover Type: "<<b.BookCover<<endl;
}
int main(){
//declaring two variables of Book type
struct Book a, b;
//calling getData to read data from user
getData(a);
//printing the data of object a
printData(a);
getData(b);
printData(b);
return 0;
}
Output:
if it helps you, do upvote as it motivates us a lot!