Thread: declaring and using functions in a class

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    32

    declaring and using functions in a class

    The point of my program is to read in a file that lists people like this:

    first name, last name, age, if hispanic? , if hispanic - hispanic type, race, disability

    So if a person is hisapnic, represented by 'H' then the type of hispanic they are follows. If they are not hispanic, 'N', then thier race follows. Being hisapnic is not your race, you can be hispanic and another race. I have the basic class made up but am having trouble to get all of the data to get to a file after being sorted. I can not figure out a way to tell if they are hispanic and if so print out their type and if not just move on to race. I've tried using a bool but I get an error and think I am not writing the code correctly. Below is the code I have written so far.

    Code:
    #pragma once
    #include <string>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    class peopleClass
    {
    private:
        string fname, lname, race, citizen, disability,hispanictype;
    	int age;
    	char hispanic;
    public:
        peopleClass(){;}
        string getFname()const{return fname;}
        string getLname()const{return lname;}
        string getRace()const{return race;}
        string getCitizen()const{return citizen;}
        string getDisability()const{return disability;}
        string getHispanictype () const {return hispanictype;}
    	int getAge()const{return age;}
    	char getHispanic()const {return hispanic;}
        void setFname(string newName){fname=newName;}
        void setLname(string newName){lname=newName;}
        void setRace(string newRace){race=newRace;}
        void setCitizen(string newCitizen){citizen=newCitizen;}
        void setDisability(string newDisability){disability=newDisability;}
    	void setHispanictype (string newHispanictype) {hispanictype=newHispanictype;}
        void setAge(int newAge){age=newAge;}
        void setHispanic(char newHispanic){hispanic=newHispanic;}
    	
    	//declaring the bool to determin if hispanic or not
        bool isHispanic (const peopleClass&) const;
    
        friend bool operator < (const peopleClass &left, const peopleClass &right);
        friend bool operator <= (const peopleClass &left, const peopleClass &right);
        friend bool operator > (const peopleClass &left, const peopleClass &right);
        friend bool operator >= (const peopleClass &left, const peopleClass &right);
        friend bool operator == (const peopleClass &left, const peopleClass &right);
        friend bool operator != (const peopleClass &left, const peopleClass &right);
    
        friend ostream & operator << (ostream &out, const peopleClass &right);
        friend istream & operator >> (istream &in, peopleClass &right);
    
    
    };
    
    //declaration of bool, if the data is 'H' then they are hispanic
    
    bool peopleClass::isHispanic (const peopleClass& getHis) const
    {
    	if peopleClass.getHispanic = 'H';
    	return true;
    }
    
    stream & operator << (ostream &out, const peopleClass &right)
    {
        out << setw(15) << right.lname 
            << setw(15) << right.fname
            << setw(8) << right.age
            << setw(8) << right.hispanic;
    		
            //trying to use the bool to see if hispanic, if so print out type of hispanic
    	if (peopleClass.isHispanic (hispanic))
    	out << setw(8) << right.hispanictype;
           
    	out << setw(8) << right.race
            <<setw(8)<< right.citizen
            <<setw(8)<< right.disability;
    
        return out;
    }
    If any one can help me out and see if I'm doing something worng or give a suggestion I would appreciate it. If yu have questions just ask.

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    nevermind I got it thx

Popular pages Recent additions subscribe to a feed