|
-
string array in c++
can somebody help me:(
i don't know what's wrong with my program:
this is my header file:
// StudentInformation.h file
#include <string> // uses string class
using std::string;
// StudentInformation class definition
class StudentInformation
{
public:
const static int students = 30; // constant number of student in the class
studentInformation ( string, string, double ); // constructor that initialize the firstname, lastname and Finalscore.
void setFirstName ( string ); // function that set the first name
string getFirstName (); // function that get the first name
void setLastName ( string ); // function that set the last name
string getLastName (); // function that get the last name
void setFinalScore ( double ); // function that set the final score
double getFinalScore (); // function that get the final score
void print (); // function that print the first name, last name and the final score
void printGrades (); // function that print all the students first name, last name and the final grade
double lowestScore (); // function that determine the lowest score
double highestScore (); // function that determine the highest score
double avgScore (); // function that determine the average score
void add ( string, string, double );
private:
string firstName; // firstname for this student information class
string lastName; // lastname for this student information class
double finalScore; // final score for this student information class
string fName[ students ]; // array of students' first name for the student information class
string lName[ students ]; // array of students' last name for the student information class
double fScore[ students ]; // array of student final score for the student information class
}; // end class student information
then this is my .cpp file:
// StudentInformation II.cpp
// Define class studentInformation that contains firstName, lastName, finalScore data
// and member functions to set and get its value.
#include <iostream> // allows program to perform input and output data
// to the screen
using namespace std;
#include <string> // program uses C++ standard string class
using namespace std;
#include <iomanip>
using namespace std;
#include "StudentInformation II.h"
// StudentInformation constructor initializes header, firstname and
// lastname with string supplied as argument and the array finalScore.
StudentInformation::StudentInformation( string f, string l, double s )
{
setFirstName( f ); // initialize firstName
setLastName( l ); // initialize lastName
setFinalScore(s);// initialize finalScore
} // end of constructor
void add( string f, string l, double s )
{
static double max = 0; // initialize first time add is called
// if max is less than students, copy firstName, lastName and finalScore into their respective arrays.
if ( max < students )
{
string fName[ max ] = firstName; // store firstName in array firstName
string lName[ max ] = lastName; // store lastName in array lastName
string fScore[ max ] = finalScore; // store finalScore in array finalScore
max++; // increment max by 1
}
} // end of constructor
// function that gets the first name
string StudentInformation::getFirstName()
{
return firstName; // return object's firstName
} // end function getFirstName
// function that sets the first name
void StudentInformation::setFirstName( string f )
{
firstName = f; // store the first name in the object
} // end function setFirstName
// function that gets the last name
string StudentInformation::getLastName()
{
return lastName; // return object's lastName
} // end function getLastName
// function that sets the last name
void StudentInformation::setLastName( string l )
{
lastName = l; // store the last name in the object
} // end function setLastName
// function that gets the finalScore
double StudentInformation::getFinalScore()
{
return finalScore; // return object's finalScore
} // end function getFinalScore
//function that sets the finalScore
void StudentInformation::setFinalScore( double s )
{
finalScore = s; // store the final score in the object
} // end function setFinalScore
// find minimum score
double StudentInformation::lowestScore()
{
double lowScore = 100; // assume lowest grade is 100
// loop through finalScore array
for ( int student = 0; student < max; student++ )
{
// if current score lower than lowScore, assign it to lowScore
if ( fScore[ student ] < lowScore )
lowScore = fScore[ student ]; // new lowest score
} // end the for loop
return lowScore; // return lowest score
} // end function lowestScore
// find maximum score
double StudentInformation::highestScore()
{
double highScore = 0; // assume highest score is 0
// loop through finalScore array
for ( int student = 0; student < max; student++ )
{
// if current score higher than highScore, assign it to highGrade
if ( fScore[ student ] > highScore )
highScore = fScore[ student ];
} // end for
return highScore; // return highest grade
} // end function highestScore
// find average score
double StudentInformation::avgScore()
{
double total = 0; // initialize total
// sum scores in array
for ( int student = 0; student < max; student++ )
total += fScore[ student ];
// return average of scores
return total / max;
} // end function average score
// function that print first name, last name and the final grade of all the students
void StudentInformation::printGrades()
{
// output each student grade
for ( int student = 0; student < max; student++ )
{
if ( fScore[ student ] >= 90 ) // if final score is more than 90, print Final Grade is A
cout<< "\n" << fName[ student ] << setw(10) << lName[ student ] << setw(10) << "Final Grade is A";
else if ( fScore[ student ] >= 80 ) // if final score is more than 80, print Final Grade is B
cout<< "\n" << fName[ student ] << setw(10) << lName[ student ] << setw(10) << "Final Grade is B";
else if ( fScore[ student ] >= 70 ) // if final score is more than 70, print Final Grade is C
cout<< "\n" << fName[ student ] << setw(10) << lName[ student ] << setw(10) << "Final Grade is C";
else if ( fScore[ student ] < 70 ) // if final score is less than 70, print Final Grade is F
cout<< "\n" << fName[ student ] << setw(10) << lName[ student ] << setw(10) << "Final Grade is F";
} // end for loop
} // end function that print the grades of all the students
// function that print first name, last name and finalScore
void StudentInformation::print()
{
cout<< "\n\nFirst Name" << setw(10) << "Last Name" << setw(10) << "Final Score\n\n";
// output each student's score
for ( int student = 0; student < max; student++ )
cout<< fName[ student ] << setw(10) << lName[ student ] << setw(10) << fScore[ student ] <<"\n";
} // end function print
now, this is my main() file:
// function main of StudentInformation II.cpp
#include <iostream>
using namespace std;
#include "StudentInformation II.h" // Include definition of class StudentInformation II
// function main begins program execution
int main()
{
// create one studentInformation object
StudentInformation myStudentInformation1( "Emeric", "Bechi", 95);
myStudentInformation1.print();
StudentInformation myStudentInformation2( "Isaac", "Newton", 100 );
myStudentInformation2.print();
system ("pause");
} // end main
now, this is the errors that i get:
5 C:\Dev-Cpp\StudentInformationIV.cpp In file included from C:\Dev-Cpp\StudentInformationIV.cpp
11 C:\Dev-Cpp\StudentInformation II.h ISO C++ forbids declaration of `studentInformation' with no type
C:\Dev-Cpp\StudentInformationIV.cpp In function `int main()':
11 C:\Dev-Cpp\StudentInformationIV.cpp no matching function for call to `StudentInformation::StudentInformation(const char[7], const char[6], int)'
Similar Threads
-
By athomas42 in forum .NET
Replies: 1
Last Post: 06-25-2007, 04:54 PM
-
Replies: 0
Last Post: 01-17-2006, 07:23 PM
-
By mdengler in forum ASP.NET
Replies: 0
Last Post: 11-26-2002, 02:32 PM
-
By Gastao Woelfert in forum VB Classic
Replies: 2
Last Post: 09-01-2000, 11:36 AM
-
By Julian Milano in forum VB Classic
Replies: 0
Last Post: 08-10-2000, 09:16 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks