1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
const int MAXLEN = 100;
struct person
{
char fname[MAXLEN];
char sname[MAXLEN];
int age;
double height;
double weight;
}nameof, personcpy;
person fillperson(struct person&, const char fname[], const char sname[], int age, double height, double weight);
person makecopy(struct person&, struct person&);
int printperson(struct person);
int main()
{
struct person fred, fredcpy;
fillperson(fred, "fred", "murphy", 22, 180.0, 83.2);
makecopy(fred, fredcpy);
printperson(fredcpy);
return 0;
}
person fillperson(struct person &nameof, const char &fname, const char &sname, int age, double height, double weight)
{
nameof.fname = fname;
nameof.sname = sname;
nameof.age = age;
nameof.height = height;
nameof.weight = weight;
return nameof;
}
person makecopy(struct person &nameof, struct person &personcpy)
{
//Copy the 'person' struct items to 'personcpy'
strcpy(personcpy.fname,nameof.fname);
strcpy(personcpy.sname,nameof.sname);
personcpy.age=nameof.age;
personcpy.height=nameof.height;
personcpy.weight=nameof.weight;
return personcpy;
}
int printperson(struct person &personcpy)
{
//Should output the copied content to the screen
cout << "First Name: " <<personcpy.fname<< endl;
cout << "Surname: " <<personcpy.sname <<endl;
cout << "Age: " <<personcpy.age << endl;
cout << "Height: " <<personcpy.height << endl;
cout << "Weight: " <<personcpy.weight <<endl;
return 0;
}
|