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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#include <iostream>
using namespace std;
class CD
{
public:
static const int num = 100;
char publisher[num], title[num], location[num];
int year;
public:
void virtual input()=0;
void virtual output()=0;
};
class Classical: public CD
{
protected:
static const int num = 100;
char composer[num], conductor[num];
public:
void virtual input()=0;
void virtual output()=0;
};
class Popular: public CD
{
private:
static const int num=100;
char name_of_the_band[num], composer[num], leading_performer[num];
public:
void input()
{ cout << "\nPublisher : ";
cin >> publisher;
cout << "Title : ";
cin >> title;
cout << "Location : ";
cin >> location;
cout << "Year : ";
cin >> year;
cout << "Name of the band : ";
cin >> name_of_the_band;
cout << "Composer : ";
cin >> composer;
cout << "Leading performer: ";
cin >> leading_performer;
}
void output()
{
cout << "\nPublisher : " << publisher;
cout << "\nTitle : " << title;
cout << "\nLocation : " << location;
cout << "\nYear : " << year;
cout << "\nName of the band : " << name_of_the_band;
cout << "\nComposer : " << composer;
cout << "\nLeading performer : " << leading_performer;
}
};
class Symphony: public Classical
{
private: static const int num=100;
char orchestra[num], location[num];
public: void input(){
cout << "\nPublisher: ";
cin >> publisher;
cout << "Title : ";
cin >> title;
cout << "Location : ";
cin >> location;
cout << "Year : ";
cin >> year;
cout << "Composer : ";
cin >> composer;
cout << "Conductor: ";
cin >> conductor;
cout << "Orchestra: ";
cin >> orchestra;
cout << "Location : ";
cin >> location;}
void output()
{ cout << "\nPublisher :" << publisher;
cout << "\nTitle :" << title;
cout << "\nLocation :" << location;
cout << "\nYear :" << year;
cout << "\nComposer :" << composer;
cout << "\nConductor :" << conductor;
cout << "\nOrchestra :" << orchestra;
cout << "\nLocation :" << location;}};
void ShellSort(CD *arr[],int n); //function prototype for our Shell sort algorithm
void main()
{
CD *cdptr[100]; //pointer declaration for each of our class
Popular *popptr;
Symphony *symptr;
int n=0, choose, symphonyCD, popularCD, pop;
char terminate;
cout << "\t\tEnter 2 or more CD-s to sort!" << endl;
do // do-while statement which allows the user to enter data and terminate the program when he wants
{
cout << "\n1.Classical";
cout << "\n2.Popular";
cout << "\n3.Sort";
cout << "\n4.Display";
cout << "\n5.Terminate program";
cout << endl << endl;
cout << "\nChoose category: ";
cin>>choose;
switch(choose) //switch for the user to choose the type of input
{
case 1:
cout << "\nChoose category: ";
cout << "\n1.Symphony";
cout << endl << endl;
cin >> pop;
if(pop==1) //if-else statement to chose the type of classical CD
{
cout << "\nEnter number of symphony cd: ";
cin >> symphonyCD;
int static b;
for(int i=0; i<symphonyCD;i++)
{
cout << "\nNr. " << ++b << endl;
symptr = new Symphony;
symptr->input();
cdptr[n++]=symptr;
}
}
else
cout << "\nNot recognized value!";
break;
case 2:
cout << "\nEnter number of popular cd: ";
cin >> popularCD;
int static a;
for(int i=0; i<popularCD;i++)
{
cout << "\nNr. " << ++a << endl;
popptr = new Popular;
popptr->input();
cdptr[n++]=popptr;
}
break;
case 3:
ShellSort(cdptr,100); //function call statement for our Shell Sort algorithm
break;
case 4:
if(n==0)
cout << "\nNo data entered!" << endl;
for(int i=0; i<n;i++)
{
cdptr[i]->output();
cout << endl;
}
break;
case 5:
cout << "\nDo you want to terminate the program? (y/n)";
cin >> terminate;
break;
default:
cout << "\nNot recognized value!" << endl;
}
}while(terminate!='y');
system("pause");
}
void ShellSort(CD *arr[],int n)
{
int i,j,increment;
CD *temp;
for(increment=n/2; increment>0; increment /= 2)
{
for(i=increment; i<n; i++)
{
temp=arr[i];
for(j=i; j>=increment; j -= increment)
{
if(temp->title < arr[j-increment]->title)
{
arr[j] = arr[j-increment];
}
else break;}
arr[j] = temp;}}}
|