Last active
June 30, 2022 13:55
-
-
Save Yousif-FJ/8cd70c8856afab225da41ef1e28b7a1a to your computer and use it in GitHub Desktop.
Q/Create class Book_Store that have the following data members (ISBN (int), book name (string), and number of copies (int)). The class have the following functions: • Input function to enter the Book_Store information. • Print function to display the Book_Store information. • In the main class use array of objects size (5) to test the functions.…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<conio.h> | |
#include<string> | |
using namespace std; | |
class Book_Store | |
{ | |
public: | |
void input(); | |
void print(); | |
friend void sort(Book_Store[5]); | |
private: | |
int ISBN; | |
string book_name; | |
int number_of_copies; | |
}; | |
void sort(Book_Store b[5]) { | |
for (int i = 0; i < 5; i++) | |
{ | |
for (int j = i+1; j < 5; j++) | |
{ | |
if (b[i].number_of_copies > b[j].number_of_copies) | |
{ | |
Book_Store temp = b[i]; | |
b[i] = b[j]; | |
b[j] = temp; | |
} | |
} | |
} | |
} | |
void Book_Store::input(){ | |
cout << "Enter ISBN, Book Name and Number of copies"<<endl; | |
cin >> ISBN; | |
cin >> book_name; | |
cin >> number_of_copies; | |
} | |
void Book_Store::print(){ | |
cout << "ISBN = " << ISBN << endl; | |
cout << "Book Name = " << book_name << endl; | |
cout << "Number of copies = " << number_of_copies << endl; | |
} | |
void main() | |
{ | |
Book_Store a[5]; | |
for (int i = 0; i < 5; i++) | |
{ | |
a[i].input(); | |
} | |
cout << "sorting" << endl; | |
sort(a); | |
for (int i = 0; i < 5; i++) | |
{ | |
a[i].print(); | |
} | |
_getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The question