By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Help with program using classes

P: n/a
Please help. The code below will compile and run using the Dev C
compiler, but not the Visual C++ 2005 express edition. I need it to
run in the express editions. any suggestions?

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using std::cout;
using std::cin;

class student

{
public:
student();

void student1Input(string fName, string lName, int id);
void student2Input(string fName, string lName, int id);

int student1maxMin();
int student2maxMin();

private:

int id, max, min;

double sum, avg;

char fName, lName;

};

student::student()

{

}

void student::student1Input(string fName, string lName, int id)

{
cout<<"\n..........Enter first student's information........\n";

cout<<"Student's ID: ";

cin>>id;

cout<<"First Name: ";

cin>>fName;

cout<<"Last Name: ";

cin>>lName;

cout<<"Grades: 95 78 26 92 27 46 89 83 78 90";

cout<<endl;

sum = 95+78+26+92+27+46+89+83+78+90;

avg = sum/10;

cout<<"Average: "<<avg;

cout<<"\nStudent 1: ";

int array[] = {95,78,26,92,27,46,89,83,78,90 };

int elements = sizeof(array) / sizeof(int);

std::sort(array, array + elements);

for (int i = 0; i < elements; ++i) std::cout<< array[i] << ' ';

cout<<endl;

cout<<endl;

}

void student::student2Input(string fName, string lName, int id)

{
cout<<"\n..........Enter second student's information........\n";

cout<<"Student's ID: ";

cin>>id;

cout<<"First Name: ";

cin>>fName;

cout<<"Last Name: ";

cin>>lName;

cout<<"Grades: 100 98 97 67 59 100 98 76 83 85";

cout<<endl;

sum = 100+98+97+67+59+100+98+76+83+85;

avg = sum/10;

cout<<"Average: "<<avg;

cout<<"\nStudent 2:";

int array[] = {100,98,97,67,59,100,98,76,83,85 };

int elements = sizeof(array) / sizeof(int);

std::sort(array, array + elements);

for (int i = 0; i < elements; ++i) std::cout<<array[i] << ' ';

cout<<endl;

cout<<endl;
}

int student::student1maxMin()

{
int array[] = {95,78,26,92,27,46,89,83,78,90 };

max = array[0];

for(int i = 0; i < 10; i++)

if( max < array[i] )

max = array[i];

min = array[0];

for(int i = 0; i < 10; i++)

if( min array[i] )

min = array[i];

cout<<"1\t \t \t "<<min<<"\t \t \t "<<max<<endl;

}

int student::student2maxMin()

{

int array[] = {100,98,97,67,59,100,98,76,83,85 };

max = array[0];

for(int i = 0; i < 10; i++)

if( max < array[i] )

max = array[i];

min = array[0];

for(int i = 0; i < 10; i++)

if( min array[i] )

min = array[i];

cout<<"2\t \t \t "<<min<<"\t \t \t "<<max<<endl;

}

int main()

{

string fName, lName; int id;

student averages;

averages.student1Input(fName, lName, id);

averages.student2Input(fName, lName, id);

cout<<"Student\t \t \t Lowest\t \t \tHigest\n";
cout<<"------------------------------------------------------\n";

averages.student1maxMin();

averages.student2maxMin();

return 0;

}

Sep 30 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Just a few things need to be changed, you need to change

int student::student1maxMin()
and
int student::student2maxMin()

to

void student::student1maxMin()
and
void student::student2maxMin()

respectively as they do not return an int value, also you must give the
variable "id" in int main() a value, for example:

string fName, lName; int id;
becomes
string fName, lName; int id = 0;

Hope this helped

Sep 30 '06 #2

P: n/a
I forgot to mention,
you must change

int student1maxMin();
&
int student2maxMin();

into

void student1maxMin();
&
void student2maxMin();

in your declarations

Sep 30 '06 #3

P: n/a
"chaching" <jd*******@aol.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com
Please help. The code below will compile and run using the Dev C
compiler, but not the Visual C++ 2005 express edition. I need it to
run in the express editions. any suggestions?
Yes, I suggest you tell us what the problem is. Is it not compiling? If so,
what are the error messages? Is it not running properly? If so, tell us both
the expected and the actual behaviour.

Your program doesn't compile for me because student::student1maxMin and
student::student2maxMin are declared as returning an int but don't return an
int. So change the return type to void or return an int.

Your use of the id variable is also bizarre, but your functions are
obviously unfinished, so now may not be the time to talk about that.
--
John Carson
Sep 30 '06 #4

P: n/a
Thank you so much! I made the changes and the program ran smooth as a
whistle. Again, thanks for the help!
Th********@gmail.com wrote:
I forgot to mention,
you must change

int student1maxMin();
&
int student2maxMin();

into

void student1maxMin();
&
void student2maxMin();

in your declarations
Oct 1 '06 #5

P: n/a

<Th********@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>I forgot to mention,
you must change

int student1maxMin();
&
int student2maxMin();

into

void student1maxMin();
&
void student2maxMin();

in your declarations
Is this in reply to something? Are we supposed to go find the post this
replies to and read it, then come back here and read this? Please quote the
relevant portion(s) of what you're responding to. This isn't a chat room.

-Howard

Oct 2 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.