Thank you for responding, although I'm afraid I still can't fix what was left. I tried making a few changes, but I'm still getting errors. Any more help would be greatly appreciated.
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
|
#include <iostream>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <vector>
using namespace std;
struct StudentRecord {
char ID[10];
string Name;
int exam [4];
double average;
};
void getStudent(StudentRecord &stu) {
string ID;
cout << "Enter the student's ID number: ";
cin >> stu.ID;
cin.ignore();
while (strlen(stu.ID) != 10) {
cout << "The Student ID must have 9 characters. " << endl;
cout << "Enter the student's ID: ";
cin >> stu.ID;
}
string Name;
cout << "Enter the student's name. " << endl;
getline (cin, stu.Name);
while (strlen(stu.Name) < 1 || strlen(stu.Name) > 30) {
cout << "Error: The student's name must be between 1 and 30 characters. " << endl;
cout << "Enter the student's name: ";
cin >> stu.Name;
}
int input;
char examarray[4];
cout << "Please enter four exam scores: " << endl;
for (input = 0; input<4; input++) {
cout << "Exam " << input << ": ";
cin >> examarray[input];
while (input < 0 || input > 100) {
cout << "Error: Please enter a score from 0 - 100. " << endl;
cout << "Exam " << input << ": ";
}
}
double average = 0;
int count = sizeof(examarray) / sizeof(int);
for (size_t i = 0; i< count; ++i) {
total += examarray[i]; }
double = (double/4);
return;
}
void printAllStudents(int &stu, &size)
{
int i;
cout << "Index";
cout << setw (10);
cout << "ID";
cout << setw (20);
cout << "Name";
cout << setw (15);
cout << "Exam Grades";
cout << setw (10);
cout << "Average" << endl;
while (int i=0; i<size; i++;) {
printStudent(i);
}
}
void printStudent(StudentRecord &stu) {
cout << i;
cout << setw (10);
cout << StudentRecords[i].ID << setw (20);
cout << StudentRecords[i].Name << setw (15);
cout << StudentRecords[i].exam << setw (10);
cout << StudentRecords[i].average << endl;
cout << setprecision (2) << studentRecords[i].average << endl;
return;
}
void printSelectedStudent(StudentRecord &stu, &size) {
int index;
cout << "Enter the student's index number: ";
cin >> index;
if (index < 0 || index > size) {
cout << "Error: Not a valid index number. ";
return;
}
else
printStudent(&size);
return;
}
void getAllStudents(StudentRecord &stu, &size){
int i;
cout << "Enter the total number of students: ";
cin >> size;
while (size < 1 || size > 32){
cout << "Error: Enter a class size from 1 - 32" << endl;
cout << "Enter the total number of students: ";
cin >> size;
}
for (int i=0; i<size; i++) {
getStudent(StudentRecord &stu);
}
return;
}
int main() {
int totalsize;
int StudentRecords[totalsize];
int selection;
cout << " ======================================== \n 1. Enter student data for the class \n 2. Print all student records \n 3. Print a single student record \n \n 0. Exit \n ======================================= \n Enter Selection: " << endl;
cin >> selection;
while (selection < 0 || selection > 3) {
cout << "Error: Input one of the choices in the menu: \n";
cin >> selection;
}
if (selection == 0)
return 0;
else if (selection == 1) {
getAllStudents(StudentRecords, totalsize);
totalsize++;
}
else if (selection == 2) {
if (StudentRecords < 1) {
cout << "Error: Enter a student record first. " << endl;
return 0;
}
else {
printAllStudents(StudentRecords);
}
}
else if (selection == 3) {
if (StudentRecords < 1) {
cout << "Error: Enter a student record first. " << endl;
}
printSelectedStudent(StudentRecords);
}
}
| |
Errors:
l08.cpp: In function ‘void getStudent(StudentRecord&)’:
l08.cpp:31: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘size_t strlen(const char*)’
l08.cpp:31: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘size_t strlen(const char*)’
l08.cpp:51: error: ‘total’ was not declared in this scope
l08.cpp:52: error: expected unqualified-id before ‘=’ token
l08.cpp: At global scope:
l08.cpp:60: error: expected identifier before ‘&’ token
l08.cpp: In function ‘void printAllStudents(int&, int&)’:
l08.cpp:72: error: expected `)' before ‘;’ token
l08.cpp:72: error: expected primary-expression before ‘)’ token
l08.cpp:72: error: expected `;' before ‘)’ token
l08.cpp: In function ‘void printStudent(StudentRecord&)’:
l08.cpp:79: error: ‘i’ was not declared in this scope
l08.cpp:81: error: ‘StudentRecords’ was not declared in this scope
l08.cpp:85: error: ‘studentRecords’ was not declared in this scope
l08.cpp: At global scope:
l08.cpp:90: error: expected identifier before ‘&’ token
l08.cpp: In function ‘void printSelectedStudent(StudentRecord&, int&)’:
l08.cpp:99: error: invalid initialization of non-const reference of type ‘StudentRecord&’ from a temporary of type ‘int*’
l08.cpp:78: error: in passing argument 1 of ‘void printStudent(StudentRecord&)’
l08.cpp: At global scope:
l08.cpp:105: error: expected identifier before ‘&’ token
l08.cpp: In function ‘void getAllStudents(StudentRecord&, int&)’:
l08.cpp:115: error: expected primary-expression before ‘&’ token
l08.cpp: In function ‘int main()’:
l08.cpp:137: error: invalid initialization of non-const reference of type ‘StudentRecord&’ from a temporary of type ‘int*’
l08.cpp:105: error: in passing argument 1 of ‘void getAllStudents(StudentRecord&, int&)’
l08.cpp:141: error: ISO C++ forbids comparison between pointer and integer
l08.cpp:146: error: invalid initialization of non-const reference of type ‘int&’ from a temporary of type ‘int*’
l08.cpp:60: error: in passing argument 1 of ‘void printAllStudents(int&, int&)’
l08.cpp:150: error: ISO C++ forbids comparison between pointer and integer
l08.cpp:153: error: invalid initialization of non-const reference of type ‘StudentRecord&’ from a temporary of type ‘int*’
l08.cpp:90: error: in passing argument 1 of ‘void printSelectedStudent(StudentRecord&, int&)’