Sort the data saved using shell algorithm. But it won't work in my case

closed account (E607ko23)
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
#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 *num[], int n);
void main()
{	CD *cdptr[100];
	Popular *popptr;
	Symphony *symptr;
	int n=0, choose, operaCD, symphonyCD, popularCD, pop;
	char terminate;
	do
	{		cout << "\n1.Classical";
			cout << "\n2.Popular";
			cout << "\n3.Sort";
			cout << "\n4.Display";
			cout << "\nChoose category: ";
			cin>>choose; switch(choose){
			case 1:
				cout << "\nChoose category: ";
				cout << "\n1.Symphony";
			    cout << endl << endl;
				cin >> pop;
				if(pop==1)
				{	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); break;
			case 4:
				if(n==0) cout << "\nNo data entered!" << endl;
				for(int i=0; i<n;i++)
				{cdptr[i]->output(); cout << endl;}
				break;}
	}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;}}}
Last edited on
closed account (E607ko23)
If I implement the sort algorithm in a more simple program it works just fine.
Topic archived. No new replies allowed.