class problem

This is a discussion on class problem within the C++ Programming forums, part of the General Programming Boards category; Here is my program. I'm not completly done yet, but I'm getting an error message when I compile and I ...

  1. #1
    Registered User Birdhaus's Avatar
    Join Date
    Nov 2005
    Posts
    11

    Question class problem

    Here is my program. I'm not completly done yet, but I'm getting an error message when I compile and I can't figure out what I'm doing wrong either with the way I wrote the class or the way I called it.
    Code:
    #include <iostream>
    #include <iomanip>
    #include <math.h>
    #include <ctype.h>
    #include <string.h>
    #include <fstream>
    
    using namespace std;
    
    class patient
    {
     public:
       char Name[30];
       int amLevel;
       int noonLevel;
       int pmLevel;
       
       patient();
       patient(char*, int, int, int);
       
       void toString(char*);
       
     private:  
       int checkAmLevel();
       int checkNoonLevel();
       int checkPmLevel();
       double aveLevel();
       void allLevelsOk();
       void getAmLevel();
       void getNoonLevel();
       void getPmLevel();
                  
    };
    
    patient::patient()
    {
    
    strcpy(Name, "none"); 
    amLevel = 0;
    noonLevel = 0;
    pmLevel = 0;
    
    }
    
    patient::patient(char* name, int a, int n, int p)
    {
                         
    strcpy(Name, name);
    
    amLevel = a;
    noonLevel = n;
    pmLevel = p;
    
    }
    
    int patient::checkAmLevel()
    {
         
       if(amLevel > 10 && amLevel < 500)
       return 1;
       
       else
       return 0;
    }
    
    int patient::checkNoonLevel()
    {
         
       if(noonLevel > 10 && noonLevel < 500)
       return 1;
       
       else
       return 0;
         
    }
    
    int patient::checkPmLevel()
    {
         
       if(pmLevel > 10 && pmLevel < 500)
       return 1;
       
       else
       return 0;
         
    }
    
    double patient::aveLevel()
    {
       int count = 0;
       
       
         
         
    }
    
    void patient::allLevelsOk()
    {
         
    
         
    }
    
    void patient::getAmLevel()
    {
         
    
         
    }
    
    void patient::getNoonLevel()
    {
         
         
         
    }
    
    void patient::getPmLevel()
    {
         
         
         
    }
    
    void patient::toString(char* strPtr)
    {
         
       char temp[6];
       
       strcpy(strPtr, Name);
       
       strcat(strPtr, ":am: ");
       if(checkAmLevel())
         {
            sprintf(temp, "%d", amLevel);
            strcat(strPtr, temp);
            
         }
       
       else
          strcat(strPtr, "out-of-range");
           
       strcat(strPtr, " :noon: ");
       if(checkNoonLevel())
         {
            sprintf(temp, "%d", noonLevel);
            strcat(strPtr, temp);
            
         }
         
       else
          strcat(strPtr, "out-of-range");
          
       strcat(strPtr, " :pm: ");
       if(checkPmLevel())
         {
             sprintf(temp, "%d", pmLevel);
             strcat(strPtr, temp);
             
         }
         
       else
         strcat(strPtr, "out-of-range");   
         
    }
    
    int main()
    {
        
       char display[100];
       
       patient P[3];
       
       P[0].patient("Chris Henkhaus", 100, 125, 150);
       
       P[1].patient("Jane Doe", 550, 100, 175);
       
       P[2].patient("John Doe", 7, 100, 250);
       
       P[0].toString(display);
       cout << display;
       
       P[1].toString(display);
       cout << display;
       
       P[2}.toString(display);
       cout << display;
       
       return 0;
        
    }
    and when I compile I'm getting an error message that reads:
    invalid use of `class patient'

    So what am I doing wrong?
    Last edited by Birdhaus; 12-01-2005 at 02:46 PM.

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    The constructors are called when a variable is declared.
    To make a call to a constructor once a variable is declared:
    Code:
      P[0] = patient("Chris Henkhaus", 100, 125, 150);
    And make the similiar changes for others.
    Your last display thing has a "}" instead of a "]".
    And your armlevel function expects to return something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mesh Class Design problem
    By sarah22 in forum Game Programming
    Replies: 2
    Last Post: 05-20-2009, 05:52 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  3. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21