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
|
#include <iostream> //"includes" the input and output streams of the input/output stream library. This is a LIBRARY.
#include <cstdlib> //"includes" all of the standard library of the C language library.
#include <string>
#include <vector>>
using namespace std; //uses all instances of the "std" class.
//creates a string array names[] with 10 values.
int average;
int amountOfGrades; //creates an integer called amountOfGrades.
int amountOfStudents; //creates an interger called amountOfStudents.
int grades[1];
int averageArray[1][1];
string names[1];
//All functions that are not void return something. The main function should usually be void. VOID means the function does NOT return a value.
/*These four are creating FUNCTION PROTOTYPES. This is because every C++ program requires a "main" function.
*This program does include one, but in order for the compiler to recognize these functions and
*call them in the main function, they must be "announced" earlier in the program, or coded before
*the main function. Either way is okay with the compiler.*/
int getInt()
{
int x;
cin >> x;
return x;
}
double getDouble()
{
double x;
cin >> x;
return x;
}
char getChar()
{
char x;
cin >> x;
return x;
}
string getString()
{
string x;
cin >> x;
return x;
}
void calcAverage(int array[],string array2[], int students, int grades)
{
int average;
for(int i = 0; i<students; i++)
{
for(int j = 0; j<grades; j++)
averageArray[i][j] = array[i],array2[j];
}
}
void printAverages(int array[],string array2[], int students, int grades)
{
for(int i = 0; i<students; i++)
{
cout<<array2[i]<<" has grades of:"<<endl;
for(int j=0; j<grades; j++)
cout<<array[j]<<", ";
}
}
int main()
{ //Braces always start functions, loops, conditions, etc
cout << "Enter the amount of grades you'd like to enter.\n"; //cout stands for "console output". It outputs a line from the console to the user.
amountOfGrades = getInt(); //the amount variable is being set to the function getInt(x) with the parameter x. It calls to that function. Explained below.
cout << "Enter the amount of students you're going to have." << endl;
amountOfStudents = getInt();
for (int i = 0; i < amountOfStudents; i++) //begins a for loop. A for loop has the initializer, when the loop starts, creates the "end-er", what ends the loop, and then the incrementer.
//This for loop starts an integer count at zero, a LOCAL VARIABLE, i to zero. The loop ends when i is less than the variable 'amountOfStudents', and it increments the variable 'i' by one everytime the loop finishes.
{
cout << "Enter the name of the student."; //prints the line telling the user to enter a string of the students name.
names[i] = getString(); //sets the array names of POSITION [i] (same one in the for loop) to equal whatever the user inputs into the getString(x) function. It's a function CALL.
for (int j = 0; j < amountOfGrades; j++)
{ //creates another for loop, with j as the starter, j less than the amountOfGrades, and increments j by 1 everytime the loop restarts.
cout << "Enter the grade." << endl; //tells the user to enter a grade. endl ends the line.
grades[j] = getDouble(); //sets the array grades of POSITION[j] to the function getDouble().
}
}
calcAverage(grades, names, amountOfStudents, amountOfGrades);
printAverages(grades, names, amountOfStudents, amountOfGrades);
system("Pause"); //pauses the system. Just utilize this
return 0;
}
|