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
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
using namespace std;
const int s = 12, p = 6;
int x[s][p], size = 3;
string randstr();
void menu ();
void displayTable(int [][p], int);
void sort(int [][p], int);
int main()
{
int choice;
displayTable(x, s);
do
{
menu();
cout << "\n\nEnter desired output [1 - 4]: ";
cin >> choice;
if(choice == 1)
{
}
if(choice == 2)
{
sort(x, s);
displayTable(x, s);
}
if(choice == 3)
{
sort(x, s);
displayTable(x, s);
}
if(choice == 4)
{
exit(0);
}
}
while (choice != 4);
return 0;
}
string randstr()
{
int L = 3;
string str = " ";
for(int c = 0; c < L; c++)
{
str[c] = 65 + rand() % 26;
}
return str;
}
void menu()
{
int selection;
cout << "\n1: Sort Alphebeltically"
<< "\n2: Sort Grades Increasing Order (Student)"
<< "\n3: Sort Grades Increasing Order (Project)"
<< "\n4: End Program";
}
void displayTable(int xt[][p], int student)
{
string sname;
double total, total2;
unsigned seed = time(0);
srand(seed);
cout << fixed << setprecision(2);
cout << "Names:\t\t";
for (int count = 1; count < 7; count++)
{
cout << count << "\t";
}
cout << "AVG";
cout << endl << endl;
for (int i = 0; i < student; i++)
{
for (int j = 0; j < p; j++)
{
xt[i][j] = 0 + rand() % 101;
}
}
for (int i = 0; i < student; i++)
{
sname = randstr();
cout << sname << " ";
for(int j = 0; j < p; j++)
{
cout << xt[i][j] << "\t";
}
for (int j = 0; j < p; j++)
{
total += xt[i][j];
if(j == (p-1))
{
total = total/p;
}
}
cout << total
<< endl;
total = 0;
}
cout << "AVG: ";
for (int j = 0; j < p; j++)
{
for (int i = 0; i < student; i++)
{
total2 += xt[i][j];
if(i == (student-1))
{
total2 = total2/student;
}
}
cout << total2 << "\t";
total2 = 0;
}
cout << endl;
}
void sort (int xs[][p], int sort_s)
{
bool check = true;
for (int i = 0; i < sort_s; i++)
{
for (int j = 0; j < p; j++)
{
int m = i, n = j + 1;
while(check == true)
{
if (n == p)
{
n = 0;
m++;
if (m == sort_s)
{
check = false;
break;
}
}
if(xs[i][j] > xs[m][n])
{
swap(xs[i][j], xs[m][n]);
n++;
}
}
}
}
}
|