Hi guys I am here first time. I would be grateful if you could support me (noob in C++ ) with his experience in programming, I have to find the right solution to this simple school task. Ps." Some explanation would be much appreciated. Thank You in advance guys. "
-----------------------------------------------------------------------------------------------------------------------------EXPECTED OUTPUT OF THE WORKING PROGRAM
The program should output the flowing when correct:
John
Couple: he Bill, she Betty
Couple: he Bill, she Betty
------------------------------------------------------------------------------------------------------------------------------TASK
TASK 1: Please complete the classes and functions below in a way in which function main will work correct.
------------------------------------------------------------------------------------------------------------------------------PROGRAM START
#include <iostream>
#include <cstring>
using namespace std;
class Person {
char* name;
public:
friend class Couple;
friend ostream& operator<<(ostream& str,
const Person& os);
explicit Person(const char* n);
Person(const Person& os);
Person& operator=(const Person& os);
~Person();
};
// constructor implementation
// destructor and class Person methods
class Couple {
Person *husband, *wife;
public:
friend ostream& operator<<(ostream& str,
const Couple& p);
Couple(const Person& m , const Person& z);
Couple(const Couple& p);
Couple& operator=(const Couple& p);
~Couple();
};
// constructor implementation
// destructor and class Couple methods
// overload of the operator <<
int main() {
Person *pjohn = new Person("John");
Couple *pcpl1 = new Couple(*pjohn, *(new Person("Jenny")));
Couple *pcpl2 = new Couple(*pcpl1);
cout << *pjohn << endl;
delete pjohn;
delete pcpl1;
Couple cpl3(Person("Bill"),Person("Betty"));
cpl3 = cpl3;
*pcpl2 = cpl3;
cout << *pcpl2 << endl;
delete pcpl2;
cout << cpl3 << endl;
}
------------------------------------------------------------------------------------------------------------------------------PROGRAM END
Simple UNI Task (Classes)
Moderator: Board moderators
Re: Simple UNI Task (Classes)
Guys I have already done it :>
Don't bother any more THX
Don't bother any more THX
-
- New poster
- Posts: 2
- Joined: Thu Apr 09, 2015 7:15 am
Re: Simple UNI Task (Classes)
Mr. Felix Halim has a great collection and classification about these types of problems.
*Signature*