1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with program using classes

Discussion in 'C++' started by chaching, Sep 30, 2006.

  1. chaching

    chaching New Member

    Joined:
    Sep 30, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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?
    Code:
    #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;
    
         } 
     

Share This Page