- Engineering
- Computer Science
- c modify code without condensing into one file to get...
Question: c modify code without condensing into one file to get...
Question details
c++ modify code without condensing into one file to get string to work
#include <iostream>
#include <string>
#include "people.h"
using namespace std;
/* classes */
int main()
{
Person p1;
p1.set_age(31);
p1.set_name("bob");
cout << "my age is " << p1.get_age()
<< endl;
cout << "my name is " <<
p1.get_name();
return 0;
}
----------------------------------------people.h
#ifndef PEOPLE_H_INCLUDED
#define PEOPLE_H_INCLUDED
class Person
{
private :
int age;
string name;
public :
void set_age(int);
int get_age();
void set_name(string);
string get_name();
};
#endif // PEOPLE_H_INCLUDED
--------------------------------->people.cpp
#include "people.h"
#include <iostream>
#include <string>
using namespace std;
void Person ::set_age(int value)
{
age = value;
}
int Person::get_age()
{
return age;
}
void Person::set_name(string info)
{
name = info;
}
string Person::get_name()
{
return name;
}
Solution by an expert tutor
