labs 1-6: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-24 14:03:08 +05:30
commit ad185c994e
26 changed files with 2250 additions and 0 deletions

82
lab6/16.cpp Normal file
View File

@@ -0,0 +1,82 @@
#include <iostream>
using namespace std;
class Book {
private:
char name[50];
uint id;
public:
void getData();
void putData();
};
void Book::getData() {
cout << "Name of book: ";
cin >> name;
cout << "ID of book: ";
cin >> id;
}
void Book::putData() {
cout << "Name of book: " << name << endl << "ID of book: " << id << endl;
}
class Authorities : public Book {
private:
char author[50];
char publisher[50];
public:
void getData();
void putData();
};
void Authorities::getData() {
cout << "Name of author: ";
cin >> author;
cout << "Name of publisher: ";
cin >> publisher;
}
void Authorities::putData() {
cout << "Name of author: " << author << endl
<< "Name of publisher: " << publisher << endl;
}
class Publication : public Authorities {
private:
uint pageCount;
uint year;
public:
void getData();
void putData();
};
void Publication::getData() {
cout << "Number of pages: ";
cin >> pageCount;
cout << "Year (YYYY): ";
cin >> year;
}
void Publication::putData() {
cout << "Number of pages: " << pageCount << endl << "Year: " << year << endl;
}
int main() {
Publication p[3];
for (auto &x: p) {
x.Book::getData();
x.Authorities::getData();
x.getData();
}
for (auto &x: p) {
x.Book::putData();
x.Authorities::putData();
x.putData();
}
}