Simple UNI Task (Classes)

Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.

Moderator: Board moderators

Post Reply
GlupiJas
New poster
Posts: 2
Joined: Thu Jan 24, 2013 1:39 pm

Simple UNI Task (Classes)

Post by GlupiJas » Thu Jan 24, 2013 2:01 pm

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

GlupiJas
New poster
Posts: 2
Joined: Thu Jan 24, 2013 1:39 pm

Re: Simple UNI Task (Classes)

Post by GlupiJas » Wed Feb 06, 2013 5:47 am

Guys I have already done it :>
Don't bother any more THX

jamesjogi08
New poster
Posts: 2
Joined: Thu Apr 09, 2015 7:15 am

Re: Simple UNI Task (Classes)

Post by jamesjogi08 » Mon Apr 13, 2015 9:09 pm

Mr. Felix Halim has a great collection and classification about these types of problems.
*Signature*

Post Reply

Return to “Other words”