-
November 26th, 2012, 07:16 PM
#1
Need help fixing an error
I ran the program and now lines 38, 92, 105, 108, 129, 138-140, 156-160, and 183 have these lime green colored blocks next to them and the error opens this crtexe.cpp file and highlights line number 555 in there:
Code:
mainret = main(argc, argv, envp);
My whole code is:
Code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//student Class declaration
class Student
{
private:
string name;
int id;
int *test;
int num;
void makeArray();
public:
Student();
Student(int n);
Student(string nm, int i, int n);
void setName(string nm);
void setID(int i);
void setScore(int i, int s);
string getName() const;
int getID() const;
void showScore();
void display();
~Student();
};
//makeArray allocate an int array with num elements,
//assigns the address of the array to test and assigns 0 to all elements
void Student::makeArray()
{
int size = Student::num;
int *studentArray;
studentArray = new int[num];
Student::test = studentArray;
test = 0;
}
//Student function
Student::Student()
{
setName("NONE");
setID(10);
Student::num = 3;
}
//Second student function, takes in 2 parameters
Student::Student(int n)
{
setName("None");
setID(10);
if(n > 0){
Student::num = n;
}else{
Student::num = 3;
}
makeArray();
}
//Third student function, takes in 3 parameters
Student::Student(string nm, int i, int n)
{
setName(nm);
setID(i);
if(n > 0){
Student::num = n;
}else{
Student::num = 3;
}
makeArray();
}
//sets name to nm
void Student::setName(string nm)
{
Student::name = nm;
}
//sets id to i. If i is in range of 10 - 99. If not then it sets id to 10 and prits and error
//message saying it cannot set the id to i. The error message should include the students name
//by displaying the return value of get name
void Student::setID(int i)
{
if(i >= 10 && i <= 99){
Student::id = i;
}else{
Student::id = 10;
cout << "Invalid. Can not set id to " << i << " for " << getName() << endl;
}
}
//only sets the score if index i is a valid index within the bounds of the dynamic array holding the test scores,
//and if s is a valid score in teh range of 0-100. If it doesn't meet thse conditions, an error message should display
// saying the test i cantnot be set to s. Error message should include student's name by displaying return value or getName.
void Student::setScore(int i, int s)
{
if(i < Student::num){
if(s >= 0 && s <= 100){
test[i] = s;
}else{
cout << "Invalid. Can not set test " << i << " to " << s << " for " << getName() << endl;
}
}else{
cout << "Invalid. Can not set test " << i << " to " << s << " for " << getName() << endl;
}
}
//returns the name
string Student::getName() const
{
return Student::name;
}
//returns the id
int Student::getID() const
{
return Student::id;
}
//displays the test number and the score
void Student::showScore()
{
for(int count = 0; count < Student::num; count++)
{
cout << "Test " << count << "had a score of " << test[count] << endl;
}
}
//get and display the student's information
void Student::display()
{
cout << "The Name: " << getName();
cout << "The ID: " << getID();
showScore();
cout << endl;
cout << endl;
}
//frees the array that test is pointing to
Student::~Student()
{
free(test);
}
int main()
{
//sets up the 3 students
Student a;
Student b(4);
Student c("Joe", 40, 5);
//calls the set functions
cout << "Calling the set functions";
//for student a
a.setName("Tom");
a.setID(200);
a.setID(20);
a.setScore(0, 75);
a.setScore(1, 85);
a.setScore(2, 95);
//for student b
b.setName("John");
b.setID(30);
b.setScore(0, 70);
b.setScore(1, 80);
b.setScore(2, 90);
b.setScore(3, 100);
//for student c
c.setScore(0, 90);
c.setScore(1, 91);
c.setScore(2, 92);
c.setScore(3, 93);
c.setScore(4, 94);
c.setScore(5, 95);
c.setScore(4, 105);
c.setScore(5, 105);
//the display function
a.display();
b.display();
c.display();
system("pause");
return 0;
}
Any help with why i am getting this error and how to fix it would be greatly appreciated. Thanks
Last edited by fergis911; November 26th, 2012 at 08:38 PM.
Reason: Resolved
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
|
Click Here to Expand Forum to Full Width
|