code for dh
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
|
int sort ()
{
songlist temp;
string id;
string at;
string sg;
string ab;
string rt;
string so;
char sor;
string choice;
char ch;
cout << "What would you like to Sort" << endl;
cout << "1: ID " << endl;
cout << "2: Artist " << endl;
cout << "3: Song " << endl;
cout << "4: Album" << endl;
cout << "5: Rating" << endl;
getline (cin, choice);
ch = atoi (choice.c_str());
if (ch == 1)
{
cout << "Sorting by ID" << endl;
cout << "a: Sort from low to high" << endl;
cout << "b: Sort from high to low" << endl;
getline(cin,so);
sor = atoi (so.c_str());
if (sor == 'a')
{
cout << "ascending order" << endl;
for (int n = 1; n < 9; n++)
{
//ascending sort
for (int pass = 1; pass < 9; pass++)
{
for (int row = 1; row <= 9; row ++)
{
if (library[row].ID > library [row + 1].ID)
{
temp = library [row + 1];
library [row + 1] = library [row];
library [row] = temp;
} // end of if statement
}// end of for statement
}
}
system("pause");
return 1;
}
if (sor =='b')
{
cout << " Descending sort" << endl;
for (int y = 1; y <= 9; y++)
{
library[y].ID = ' ';
for (int row = 1; row < (9 - 1); row++)
{
if (library[row].ID > library [row - 1].ID)
{
temp= library[y - 1];
library[y - 1] = library[y];
library[y] = temp;
} // end if
OPP ();
system("pause");
} // end inner for
} // end outer for
return 2;
}
}
if (ch == 2)
{
library[ch].artist = atoi (at.c_str());
for (int pass = 0; pass < 6; pass++)
{
for (int row = 0; row <= 6; row ++)
{
if (library[row].artist > library [row + 1].artist)
{
temp = library [row];
library [row] = library [row + 1];
library [row + 1] = temp;
} // end of if statement
}// end of for statement
}
}
if (ch == 3)
{
library[ch].song = atoi (sg.c_str());
for (int pass = 0; pass < 6; pass++)
{
for (int row = 0; row <= 6; row ++)
{
if (library[row].song > library [row + 1].song)
{
temp = library [row];
library [row] = library [row + 1];
library [row + 1] = temp;
} // end of if statement
}// end of for statement
}
}
if (ch == 4)
{
library[ch].album = atoi (ab.c_str());
for (int pass = 0; pass < 6; pass++)
{
for (int row = 0; row <= 6; row ++)
{
if (library[row].album > library [row + 1].album)
{
temp = library [row];
library [row] = library [row + 1];
library [row + 1] = temp;
} // end of if statement
}// end of for statement
}
}
if (ch == 5)
{
library[ch].rating = atoi (rt.c_str());
for (int pass = 0; pass < 6; pass++)
{
for (int row = 0; row <= 6; row ++)
{
if (library[row].rating > library [row + 1].rating)
{
temp = library [row];
library [row] = library [row + 1];
library [row + 1] = temp;
} // end of if statement
}// end of for statement
}
}
return 0 ;
}
|
What's "dh" ?
sorry i didn't mean for anyone to try and look at this but someone from my class
Topic archived. No new replies allowed.