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
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
const int s = 12, p = 6;
int x[s][p];
void values(int [][p], const int);
void displaytable(int [][p], const int);
void sort(int [][p], const int);
string randstr(const int);
void menu();
int main()
{
int choice;
values(x, s);
displaytable(x, s);
do
{
menu();
cout << "Enter choice: ";
cin >> choice;
if(choice == 2)
{
sort(x, s);
displaytable(x, s);
}
}
while(choice != 4);
return 0;
}
void values(int x0[][p], const int s0)
{
for (int i = 0; i < s0; i++)
{
for (int j = 0; j < p; j++)
{
x0[i][j] = 0 + rand() % 101;
}
}
}
void displaytable(int x1[][p], const int s1)
{
cout << fixed << setprecision(2);
string sname;
double total, total2;
cout << "Names:\t\t";
for(int count = 1; count < 7; count++)
{
cout << "P" << count << "\t";
}
cout << "AVER."
<< "\n\n";
for(int i = 0; i < s1; i++)
{
sname = randstr(s);
cout << sname << " ";
for(int j = 0; j < p; j++)
{
cout << x1[i][j] << "\t";
total += x1[i][j];
if (j == (p-1))
{
total = total/p;
cout << total;
cout << endl;
}
}
}
cout << "AVER. ";
for (int j = 0; j < p; j++)
{
for(int i = 0; i < s1; i++)
{
total2 += x1[i][j];
if (i == (s1-1))
{
total2 = total2/s1;
cout << total2 << "\t";
}
}
}
cout << endl;
}
string randstr(const int s)
{
int L = 3;
string name = " ";
for (int count = 0; count < s; count++)
{
name[count] = 65 + rand() % 26;
}
return name;
}
void menu()
{
cout << "\n1: Sort Alphebeltically"
<< "\n2: Sort Grades Increasing Order (Student)"
<< "\n3: Sort Grades Increasing Order (Project)"
<< "\n4: End Program";
}
void sort (int xs[][p], const int sort_s)
{
int temp;
for (int i = 0; i < sort_s; i++)
{
for (int j = 0; j < p; j++)
{
if(xs[i][j] > xs[i][j+1])
{
temp = xs[i][j];
xs[i][j] = xs[i][j+1];
xs[i][j+1] = temp;
}
}
}
}
|