Thread: expertise needed

  1. #1
    Registered User
    Join Date
    Apr 2002

    Question HELP!! on Classes

    Hi I am learning C++ on my own, but i been having problems with the classes, can you give me a hand by telling me what can i do to get the output?

    the output has to show the name, occupation, party and votes
    Thank you for your help and time;

    here's my code
    class CCandidate  
    	char m_strName[35];
    	char m_strOccupation[50];		//declaration of the variables that
    	char m_strParty[50];			//will be used for each prototype
    	int m_intVotes;
    	char name [35];
    	char occupation [50];
    	char party[50];
    	int votes;
    	void setName();  //get name from user
    	getName(char m_strName);		
    	void setOccupation();
    	getOccupation(char m_strOccupation);
    	void setParty();
    	getParty(char m_strPary);
    	void recordVotes();
    	getVotes(int m_intVotes);
    //get data for each function
    	char name[35];			//declaration of the variable 
    	cout<<"Please enter the candidate's name: "<<endl; //ask for candidate's name
    	cin>>name;  // the input is under the variable of name
    	char occupation[50];
    	cout<<" Please enter the candidate's occupation: "<<endl;
    	char party[50];
    	cout<<"Please enter the party of the candidate: "<<endl;
    	int votes;
    	cout<<"Please enter the amount of votes: "<<endl;
    // Outputs for the functions
    CCandidate::getName(char m_strName)
    	m_strName=name;	   //Substituting name to the variable m_strName for output
    	cout<<" Candidate's name is:' "<<m_strName<<" ' "<<endl;	
    CCandidate::getOccupation(char m_strOccupation)
    	cout<<" The occupation of the candidate " <<m_strName<<" is "<<m_strOccupation<<endl;
    CCandidate::getParty(char m_strParty)
    	cout<<" and the party he/she belongs is: "<<m_strParty<<endl;
    	int m_intVotesCLR = 0;		//sets the votes to 0
    CCandidate::getVotes(int m_intVotes)
    	cout<<" The candidate has "<<m_intVotes<<endl;
    void main()

    Code tags added by Kermi3
    Last edited by moenia; 11-16-2002 at 02:49 PM.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998

    Code Tags

    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you

    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    cout << "No code tags are bad";

    With Code Tags:
    for(int i=0;i<5;i++)
         cout << "This code is easy to read";
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.

    Good Luck with your program,

    Lead Moderator

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    In your main() you need to call an instance of your CLASS.
    CCandidate myCandidate;
    //from here you can call any function or public variable of your CLASS
    //Or whatever you want to call, use the name of your instance + the '.' dot 
    //and the name of the function or variable you want to call.
    I found a bunch of small errors in your code but you need to figure those out.
    My Avatar says: "Stay in School"

    Rocco is the Boy!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  5. C++ Knowledge Needed For Making Graphic Games?
    By Krak in forum C++ Programming
    Replies: 14
    Last Post: 07-11-2003, 09:11 PM