1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
class Holdings {
protected:
int callNum;
char* Title;
public:
Holdings(char* Title, int callNum);
virtual char* print();
};
class Book : public Holdings {
protected:
char* Author;
public:
Book(char* Tile , int callNum, char* Author);
virtual char* print();
};
class Recordings : public Holdings{
protected:
char* Artist;
char* Type;
public:
Recordings(char* Title, int callNum, char* Artist, char type);
virtual char* print();
};
char* Holdings::print(){
char* temp;
int length;
temp = new char[100];
strcpy(temp, "Holdings- Title: ");
strcat(temp, Title);
strcat(temp, "Call Number: ");
strcat(temp, (char*)(callNum));
length = strlen(temp);
temp[length] = 0;
return temp;
}
char* Recordings::print(){
char* temp = new char[100];
int length;
strcpy(temp, "Holdings- \t Title: ");
strcat(temp, Title);
strcat(temp, "Call Number: ");
strcat(temp, (char*)(callNum));
length = strlen(temp);
temp[length] = 0;
cout << temp << endl;
}
char* Book::print(){
char* temp = new char[100];
int length;
strcpy(temp, "Holdings- \t Title: ");
strcat(temp, Title);
strcat(temp, "Call Number: ");
strcat(temp, (char*)(callNum));
length = strlen(temp);
temp[length] = 0;
cout << temp << endl;
}
int main() {
Holdings *x[5];
for (int i = 0; i < 5; i++){
char BoR, type;
char* title;
char* a;
int callNum;
title = new char[10];
a = new char[10];
cout << "Enter B for book, R for Recording: ";
cin >> BoR;
if (BoR == 'B' || BoR == 'b'){
cout << "Enter book title: ";
cin >> title;
cout << "Enter author: ";
cin >> a;
cout << "Enter call number: ";
cin >> callNum;
x[i] = new Book(title, callNum, a);
x[i]->print();
}
else if (BoR == 'R' || BoR == 'r'){
cout << "Enter Recording title: ";
cin >> title;
cout << "Enter artist: ";
cin >> a;
cout << "Enter format: (M)P3, (W)AV, (A)IFF: ";
cin >> type;
cout << "Enter call number: ";
cin >> callNum;
x[i] = new Recordings(title, callNum, a, type);
cout << x[i]->print();
}
else{
cout << "ERROR" << endl;
}
}
return 0;
}
|