GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Dec-2008, 19:12
socal850tuner socal850tuner is offline
New Member
 
Join Date: Oct 2008
Posts: 14
socal850tuner is on a distinguished road

Class and file organizer


Well for my CSC homework I was told to make a program using classes and files to organize student information. Well I got the programming done however I can't figure out my error and I was wondering if you guys could help me debug. I will post my code and the list of errors that are coming up.

CPP / C++ / C Code:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <istream.h>

#define W setw

class student
{
        private:
                char first[20], mi[20], last[20], year[20];
                int age;
                double gpa;
        Public:
                student();
                int read(ifstream &);
                void show();
                double gpa();
                int better(double);
};

student::student() {gpa=0;}

int student::read(ifstream & IS)
{
        IS>>first>>mi>>last>>year>>age>>gpa;
        return !IS.eof();
}

void student::show()
{
	cout<<'\n'<<W(10)<<first<<W(4)<<mi<<W(15)<<last<<W(12)<<year<<W(3)<<age;
}

double student::gpa() {return gpa;}

int student::better(double bestgpa)
{
        return gpa>bestpga && !strcmp(year, "senior");
}

int main(void)
{

student s, best;
ifstream IS = "student.dat"; cout<<"\nstudent file:";
while(s.read(IS))
        {
                s.show();
                if(s.better(best.gpa())) best=s;
        }
cout<<"\n\n the best senior: "; best.show();
return 0;
}



now here are there errors that Microsoft Visual 6 found.




Code:
Compiling... gpa.cpp C:\mjk\gpa.cpp(19) : error C2514: 'student' : class has no constructors C:\mjk\gpa.cpp(11) : see declaration of 'student' C:\mjk\gpa.cpp(19) : error C2056: illegal expression C:\mjk\gpa.cpp(19) : error C2501: 'Public' : missing storage-class or type specifiers C:\mjk\gpa.cpp(22) : error C2040: 'gpa' : 'double (void)' differs in levels of indirection from 'double' C:\mjk\gpa.cpp(26) : error C2600: 'student::student' : cannot define a compiler-generated special member function (must be declared in the class first) C:\mjk\gpa.cpp(43) : error C2063: 'gpa' : not a function C:\mjk\gpa.cpp(43) : error C2040: 'gpa' : 'double (void)' differs in levels of indirection from 'double' C:\mjk\gpa.cpp(43) : fatal error C1903: unable to recover from previous error(s); stopping compilation Error executing cl.exe. gpa.obj - 8 error(s), 0 warning(s)
  #2  
Old 03-Dec-2008, 19:47
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: class and file organizer


CPP / C++ / C Code:
        Public:
                student();
Try:
CPP / C++ / C Code:
        public:
                student();
  #3  
Old 03-Dec-2008, 19:56
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: class and file organizer


Quote:
Originally Posted by socal850tuner
...I was wondering if you guys could help me debug.
Most of the errors are pretty straight-forward. Did you really try figuring out of there for yourself, or simple dump them onto us to fix for you?
  • The keyword public is not "Public".
  • gpa cannot be the name of a member variable and a member function within the same class.
  • Rethink this line:
    CPP / C++ / C Code:
    return gpa>bestpga && !strcmp(year, "senior");
There are other errors, but you should resolve these yourself.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Power Calibration Error In Nero Fix (hopefully) matt3678 Computer Hardware Forum 60 20-Aug-2009 06:04
Totally confused on assigment using linked lists Uchihanokonoha C++ Forum 2 05-Jan-2008 11:47
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Box Class, need help again :( TransformedBG C++ Forum 7 13-Nov-2006 16:11
C++ class -- Please help vnca_1 C++ Forum 3 14-Jun-2006 13:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:21.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.