
April 8th, 2003, 11:54 PM
|
|
Junior Member
|
|
Join Date: Apr 2003
Location: New York
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
String arrays + functions
I'm trying to pass a string array to a function which would populate it. Doesn't work the way I have it written below. I get a an error messages: 'string' : undeclared identifier.
PHP Code:
//Processor section
#include <iostream>
#include <string>
const int SIZE = 35; //Max number of students in class
int NumStudents;
//Function prototypes
void DisplayProgramInfo (void);
void NumOfStudents ();
void StudentData(string StudentName[], int StudentID[], double FinalGrade[]);
void ExamWeights (double Exam1Percent, double Exam2Percent, double Exam3Percent, double Exam4Percent);
using namespace std;
void main (void)
{
//Declare variables
//Number of students in class
int StudentID[SIZE];
string StudentName[SIZE];
double FinalGrade[SIZE];
//Display general info about the program
DisplayProgramInfo();
//Get number of students in class
NumOfStudents();
//Get Student data
StudentData(StudentName, StudentID, FinalGrade);
}
void DisplayProgramInfo (void)
{
//Display general info about the program
cout <<"This program will help you calculate the final grade of each student,\n"
<<"based on the average of 4 exam grades. It will also display the class average,\n"
<<"and the max and min grades for the class.\n"
<<"You can enter data for a maximum of 35 students.\n";
}
void NumOfStudents ()
{
//Get number of students in class
do {
cout <<"\nHow many students are in the class?\t";
cin >> NumStudents;
if (NumStudents > SIZE || NumStudents <= 0)
cout <<"\nYou have entred an incorrect number, please try again";
} while (NumStudents > SIZE || NumStudents <= 0);
}
void StudentData(string StudentName[], int StudentID[], double FinalGrade[])
{
//Declare variables
int i(0);
// string StudentName[SIZE];
double exam1, exam2, exam3, exam4;
double Exam1Percent(0.0), Exam2Percent(0.0); //Exam percentage weight
double Exam3Percent(0.0), Exam4Percent(0.0); //Exam percentage weight
cout << NumStudents;
//Get exam weights
ExamWeights (Exam1Percent, Exam2Percent, Exam3Percent, Exam4Percent);
//Get data
for (i=0; i < NumStudents; i++)
{
cout <<"\n\nPlease enter the student name: ";
cin >> StudentName[i];
cout <<"Please enter the ID number for " << StudentName[i] <<":\t";
cin >> StudentID[i];
cout <<"\nPlease enter the grade for the 1st exam:\t";
cin >> exam1;
cout <<"Please enter the grade for the 2nd exam:\t";
cin >> exam2;
cout <<"Please enter the grade for the 3rd exam:\t";
cin >> exam3;
cout <<"Please enter the grade for the 4th exam:\t";
cin >> exam4;
FinalGrade[i] = ((exam1*Exam1Percent) + (exam2*Exam2Percent) + (exam3*Exam3Percent) + (exam4*Exam4Percent));
}
}
|