473,659 Members | 2,488 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.showStu dent();
//changes firstname
person1.setName ("Stanko", "Brianne");
person1.showStu dent();
//changes both names
person1.setName ("Stanko", "Brianne");
person1.showStu dent();
//changes id
person1.setID(" 146926");
person1.showStu dent();
//changes to valid score
person1.setScor e(1467);
cout << " The new valid score is: " << person1.setScor e(1598) << endl;
person1.showStu dent();
//changes to invalid score
person1.setScor e(1598);
cout << " The invalid score is: " << person1.setScor e(156) << endl;
person1.showStu dent();
//changes to valid gpa
person1.setGPA( 3.5);
cout << " The new gpa is: " << person1.setGPA( 3.3) << endl;
person1.showStu dent();
//changes to invalid gpa
person1.setGPA( 3.3);
cout << " The invalid gpa is: " << person1.setGPA(-2.8) << endl;
person1.showStu dent();
person1.getDeci sion();
cout << " The student for this year:" << person1.getDeci sion() << endl;

system("pause") ;

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

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

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

}
void Student::showSt udent()
{
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::setNam e(char newFirstname[], char newLastname[])
{
strcpy(lastname , newLastname);
strcpy(firstnam e, 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::setSco re(int newScore)
{
if(newScore >= 200 && newScore <= 1600)
{
Score = newScore;
return 1;
}
else
{
return 0;
}
}
char Student::getDec ision()
{

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 1798
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.showStu dent();
//changes firstname
person1.setName ("Stanko", "Brianne");
person1.showStu dent();
//changes both names
person1.setName ("Stanko", "Brianne");
person1.showStu dent();
//changes id
person1.setID(" 146926");
person1.showStu dent();
//changes to valid score
person1.setScor e(1467);
cout << " The new valid score is: " << person1.setScor e(1598) << endl;
person1.showStu dent();
//changes to invalid score
person1.setScor e(1598);
cout << " The invalid score is: " << person1.setScor e(156) << endl;
person1.showStu dent();
//changes to valid gpa
person1.setGPA( 3.5);
cout << " The new gpa is: " << person1.setGPA( 3.3) << endl;
person1.showStu dent();
//changes to invalid gpa
person1.setGPA( 3.3);
cout << " The invalid gpa is: " << person1.setGPA(-2.8) << endl;
person1.showStu dent();
person1.getDeci sion();
cout << " The student for this year:" << person1.getDeci sion() << endl;

system("pause") ;

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

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

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

}
void Student::showSt udent()
{
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::setNam e(char newFirstname[], char newLastname[])
{
strcpy(lastname , newLastname);
strcpy(firstnam e, 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::setSco re(int newScore)
{
if(newScore >= 200 && newScore <= 1600)
{
Score = newScore;
return 1;
}
else
{
return 0;
}
}
char Student::getDec ision()
{

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
2891
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
7663
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 Dispose-Method and call the GC nothing happend!!! my Disposemethod has never been called!! so the GC dont call my Dispose-Method although I implemented IDisposable? what am i doing wrong?
1
1707
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 my books that requires a view? I can add a view to my project but i dont see where i add a frame and doc? Or can i add a view to a normal dialog box? (I dont think i can do this but if i could it would be handy Im using visual c++ 6.0...
7
1368
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 templatefields are not bind anymore. Only the boundfields are still bound. Why? and what can I do about this?
2
3944
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 key for both buttons. &button1 and &button2. They have same access key but they are in diffrent pages. Access key works only in tabpage1 for button1 and access key for second button dont work. BUT! in diffrent comp it works. Same exec run on...
16
6931
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
996
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 when uplode my file on ftp server and test it from web it dont bring me pages. befor me other php workers could have been able to this. but now i dont know what happens? can you help me i keep my new job??????
2
2707
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
2489
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 doing this, I did things in a way I thought it should work, to create the onmouseover animation of the buttons of my navigation menu. After a couple days working on it, I managed it to work almost the way I wanted it to, with 2 exceptions that I...
1
2001
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 NewWindow:=False, AddHistory:=True Application.WindowState = xlNormal Start_Timer End Sub ... and question ...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.