Help with program using classes

C

chaching

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 << ' ';

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 << ' ';

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 )

max = array;

min = array[0];

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

if( min > array )

min = array;

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 )

max = array;

min = array[0];

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

if( min > array )

min = array;

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;

}
 
T

TheReckter

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
 
T

TheReckter

I forgot to mention,
you must change

int student1maxMin();
&
int student2maxMin();

into

void student1maxMin();
&
void student2maxMin();

in your declarations
 
J

John Carson

chaching said:
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.
 
C

chaching

Thank you so much! I made the changes and the program ran smooth as a
whistle. Again, thanks for the help!
 
H

Howard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top