473,508 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i dont know what the problem is...

11 New Member
i know this is set up wrong but i didnt know how to do that--sorry. but this is my program that i have. it compiles and runs, but the values are completely wrong! can anyone help me??
#include <iostream>
#include <iomanip>

using namespace std;

class Student
{
private:
char lastname[40];
char firstname[40];
char ID[10];
double GPA;
int Score;

public:
Student(char [], char [], char [], double , int);
void showStudent();
void setName(char [], char []);
void setID(char []);
int setGPA(double );
int setScore(int );
char getDecision();

};

int main()
{

Student person1 = Student( "Stanko", "Brianne", "146926", 3.3, 1598);
Student person2 = Student( " Hartnett", " Josh", "123654", -2.8, 156);

person1.showStudent();
//changes firstname
person1.setName("Stanko", "Brianne");
person1.showStudent();
//changes both names
person1.setName("Stanko", "Brianne");
person1.showStudent();
//changes id
person1.setID("146926");
person1.showStudent();
//changes to valid score
person1.setScore(1467);
cout << " The new valid score is: " << person1.setScore(1598) << endl;
person1.showStudent();
//changes to invalid score
person1.setScore(1598);
cout << " The invalid score is: " << person1.setScore(156) << endl;
person1.showStudent();
//changes to valid gpa
person1.setGPA(3.5);
cout << " The new gpa is: " << person1.setGPA(3.3) << endl;
person1.showStudent();
//changes to invalid gpa
person1.setGPA(3.3);
cout << " The invalid gpa is: " << person1.setGPA(-2.8) << endl;
person1.showStudent();
person1.getDecision();
cout << " The student for this year:" << person1.getDecision() << endl;

system("pause");

return 0;
}
Student::Student(char newLastname[], char newFirstname[], char newID[],
double newGPA, int newScore)
{
strcpy(lastname, newLastname);
strcpy(firstname, newFirstname);
strcpy(ID, newID);

if(setGPA(newGPA) < 0)
{
cout << " Invalid answer: set to 0";
}

if(setScore(newScore) < 0)
{
cout << " Invalid answer: set to 0";
}

}
void Student::showStudent()
{
cout << endl;
cout << " last name: " << lastname[40];
cout << endl;
cout << " first name: " << firstname[40];
cout << endl;
cout << " id: " << ID[10];
cout << endl;
cout << " gpa: " << GPA;
cout << endl;
cout << " score: " << Score;
cout << endl;
}
void Student::setName(char newFirstname[], char newLastname[])
{
strcpy(lastname, newLastname);
strcpy(firstname, newFirstname);

}
void Student::setID(char newID[])
{
strcpy(ID, newID);

}
int Student::setGPA(double newGPA)
{

if(newGPA >= 0 && newGPA <= 4.0)
{
GPA = newGPA;
return 1;
}
else
{
return 0;
}
}
int Student::setScore(int newScore)
{
if(newScore >= 200 && newScore <= 1600)
{
Score = newScore;
return 1;
}
else
{
return 0;
}
}
char Student::getDecision()
{

if(GPA >= 3.5 || Score > 1300)
{
return 'a';
}
else if(GPA < 2.2 || Score < 900)
{
return 'd';
}
else
{
return 'w';
}
}
May 3 '07 #1
1 1787
ilikepython
844 Recognized Expert Contributor
i know this is set up wrong but i didnt know how to do that--sorry. but this is my program that i have. it compiles and runs, but the values are completely wrong! can anyone help me??
#include <iostream>
#include <iomanip>

using namespace std;

class Student
{
private:
char lastname[40];
char firstname[40];
char ID[10];
double GPA;
int Score;

public:
Student(char [], char [], char [], double , int);
void showStudent();
void setName(char [], char []);
void setID(char []);
int setGPA(double );
int setScore(int );
char getDecision();

};

int main()
{

Student person1 = Student( "Stanko", "Brianne", "146926", 3.3, 1598);
Student person2 = Student( " Hartnett", " Josh", "123654", -2.8, 156);

person1.showStudent();
//changes firstname
person1.setName("Stanko", "Brianne");
person1.showStudent();
//changes both names
person1.setName("Stanko", "Brianne");
person1.showStudent();
//changes id
person1.setID("146926");
person1.showStudent();
//changes to valid score
person1.setScore(1467);
cout << " The new valid score is: " << person1.setScore(1598) << endl;
person1.showStudent();
//changes to invalid score
person1.setScore(1598);
cout << " The invalid score is: " << person1.setScore(156) << endl;
person1.showStudent();
//changes to valid gpa
person1.setGPA(3.5);
cout << " The new gpa is: " << person1.setGPA(3.3) << endl;
person1.showStudent();
//changes to invalid gpa
person1.setGPA(3.3);
cout << " The invalid gpa is: " << person1.setGPA(-2.8) << endl;
person1.showStudent();
person1.getDecision();
cout << " The student for this year:" << person1.getDecision() << endl;

system("pause");

return 0;
}
Student::Student(char newLastname[], char newFirstname[], char newID[],
double newGPA, int newScore)
{
strcpy(lastname, newLastname);
strcpy(firstname, newFirstname);
strcpy(ID, newID);

if(setGPA(newGPA) < 0)
{
cout << " Invalid answer: set to 0";
}

if(setScore(newScore) < 0)
{
cout << " Invalid answer: set to 0";
}

}
void Student::showStudent()
{
cout << endl;
cout << " last name: " << lastname[40];
cout << endl;
cout << " first name: " << firstname[40];
cout << endl;
cout << " id: " << ID[10];
cout << endl;
cout << " gpa: " << GPA;
cout << endl;
cout << " score: " << Score;
cout << endl;
}
void Student::setName(char newFirstname[], char newLastname[])
{
strcpy(lastname, newLastname);
strcpy(firstname, newFirstname);

}
void Student::setID(char newID[])
{
strcpy(ID, newID);

}
int Student::setGPA(double newGPA)
{

if(newGPA >= 0 && newGPA <= 4.0)
{
GPA = newGPA;
return 1;
}
else
{
return 0;
}
}
int Student::setScore(int newScore)
{
if(newScore >= 200 && newScore <= 1600)
{
Score = newScore;
return 1;
}
else
{
return 0;
}
}
char Student::getDecision()
{

if(GPA >= 3.5 || Score > 1300)
{
return 'a';
}
else if(GPA < 2.2 || Score < 900)
{
return 'd';
}
else
{
return 'w';
}
}
The problem is that in your showStudent function, you only print out the 41st element of the name arrays. That's bad because your array only has 40 elements. You cannot print an array by just saying "cout << array_name". You have to manually go and print every element in it one by one. You should use a for loop. Also, you might want to make a function that takes an array and prints it out to save space.
Are you getting anything else as wrong values?
May 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

19
2875
by: Wouter | last post by:
Hi, I try to make when i send a <form> that he dont open a new window. Is there someone who know how i can make this whit javascript ? Greets Wouter
24
7625
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
1
1699
by: Merrua | last post by:
I dont understand how to do this I created a dialog based project and that is fine for most of my programming project, but one dialog box is going to generate a graph, and as far as i know from...
7
1361
by: Maarten | last post by:
Hi, I have a gridview (2.0), in the page load I remove a couple of columns from the gridview which I dont need. (All the columns are databound) This works fine. But after a postback all the...
2
3939
by: tasiekk | last post by:
I have 1 lil problem. I make simple Win Forms app and i put there a tab control. There i make two pages. In each page i make 1 button. In tabpage1 button1 and in tabpage2 button2. And i make access...
16
6907
by: NewToCPP | last post by:
I have seen at several places that C++ programmers writing for RealTime Embedded applications dont use Exception Handling. They dont like Throw/catch concept. WHY? Thanks.
0
989
by: maintenance | last post by:
hello I code phpnuke web site for my comunity. i need after inserting or deleting on database remotly ,redirect to original edit web page of my user panel.i do it in localhost.an it work true.but...
2
2688
by: hojjatnikan | last post by:
please help me this code 62EH&5gx0wiqoQFw is this name ( Belux) but i dont know how convert it i dont know the algorithm of this code plead help me
2
2477
by: Tiruak | last post by:
Hi there. Thanks in advance for the people reading and trying to help. I'm very begginer using flash and action script, and I tryed to do this one navigation menu. Since I dont have experience...
1
1992
by: suvaline | last post by:
I dont know much about VBA, but maybe somebody can help me ;) I have this kind of SUB .. Sub kama2() Worksheets("kama").Activate Range("A51").Select Selection.Hyperlinks(1).Follow...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.