DX little help with c++

A place general forum talk, not related to ingame discussions.
Post Reply
User avatar
captain_jack
Forum Expert
Posts: 1215
Joined: Mon Aug 13, 2007 3:11 pm
ID: 0

DX little help with c++

i got to do a project in c++ but am a bit lost and was told if i figured out this program then i could use it to heklp me with the project can anyone tell me how to put the names into set_name so they can be copied to get names

#include<iostream.h>
#include<iomanip.h>
#include<string.h>
class person
{
char name[20];
char nationality[20];
int dobday;
char dobmonth[20];
int dobyear;
char sex[6];

public:
void set_names(char names[20]){strcpy(name,names);}
char* get_name(char name1) { return name;}

void set_nationalitys(char nationalitys[20]){strcpy(nationality,nationalitys);}
char* get_nationality() { return nationality;}

void set_dobday(int dob1){dobday = dob1;}
int get_dobday() { return dobday;}

void set_dobmonths(char dobmonths[20]){strcpy(dobmonth,dobmonths);}
char* get_dobmonth() { return dobmonth;}

void set_dobyear(int dob2){dobyear=dob2;}
int get_dobyear() { return dobyear;}

void set_sex(char sexs[6]){strcpy(sex,sexs);}
char* get_sex() { return sex;}
void show();
};



class student:public person
{
char name[20];
char nationality[20];
int dobday;
char dobmonth[20];
int dobyear;
char sex[6];


public :
int id;
int reg_date;

};

void person::show()
{
cout<<get_name()<<endl;
cout<<get_nationality()<<endl;
cout<<get_dobday()<<endl;
cout<<get_dobmonth()<<endl;
cout<<get_dobyear()<<endl;
cout<<get_sex()<<endl;





}

int main()
{
person p1;
char name1[20];




p1.get_name(name1[20]);
p1.get_nationality();
p1.get_dobday();
p1.get_dobmonth();
p1.get_dobyear();
p1.get_sex();





return 0;
}
ImageImageImageImageImage click the eggs please epescially the wiered blue one
http://dragcave.net/user/arieona click my girlfriends ones too please
Harlequin
Fledgling Forumer
Posts: 157
Joined: Wed Dec 19, 2007 11:29 am
Alliance: Alcoholics Anonymous
ID: 0
Location: Cambridge, UK

Re: DX little help with c++

captain_jack wrote:i got to do a project in c++ but am a bit lost and was told if i figured out this program then i could use it to heklp me with the project can anyone tell me how to put the names into set_name so they can be copied to get names

#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#define MAX_NAME_LEN 20

class person
{
char name[MAX_NAME_LEN];

public:
void set_name(char *newname){strcpy(name,newname);}
char* get_name(char name1) { return name;}

};


The bit I've highlighted in red is completely unnecessary; get rid of it. Then, when you want to add a name, create a character array containing the name, ie.

Code: Select all

char *my_name = "Luke";

then create your person object

Code: Select all

person *me = new person;

and then to set the name:

Code: Select all

me->set_name(my_name);

and to retrieve it:

Code: Select all

char *the_name = me->get_name();

The other attributes can be done similarly.
Image
Post Reply

Return to “This, That, Those, and Them”