#pragma once
#include <string>
#include <iostream>
using namespace std ;
class Document
{
public:
Document ( ) ;
Document operator= ( const Document & d ) ;
void setText ( ) ;
string getText ( ) ;
protected:
string text ;
} ;
#include "document.h"
Document::Document ( ) : text ( "No text set" )
{ }
Document Document::operator =( const Document & d )
{
text = d.text ;
return *this ;
}
void Document::setText ( )
{
cout << "Body: " << endl ;
getline ( cin , text ) ;
}
string Document::getText ( )
{
return text ;
}
#pragma once
#include "document.h"
#include <string>
#include <iostream>
using namespace std ;
class Email : public Document
{
public:
Email ( ) ;
Email ( string s , string r , string t ) ;
Email operator =( const Email & e ) ;
void setData ( ) ;
string getSender ( ) ;
string getRecipient ( ) ;
string getTitle ( ) ;
protected:
string sender ;
string recipient ;
string title ;
} ;
#include "email.h"
Email::Email ( ) : Document ( ) , sender ( "None" ) , recipient ( "None" ) , title ( "None" )
{ }
Email::Email ( string s , string r , string t ) : Document ( ) , sender ( s ) , recipient ( r ) , title ( t )
{ }
Email Email::operator =( const Email & e )
{
Document::operator= ( e ) ;
sender = e.sender ;
recipient = e.recipient ;
title = e.title ;
return *this ;
}
void Email::setData ( )
{
cout << "From: " << flush ;
cin >> sender ;
cout << "To: " << flush ;
cin >> recipient ;
cout << "Subject: " << flush ;
cin >> title ;
cin.ignore () ;
Document::setText ( ) ;
}
string Email::getSender ( )
{
return sender ;
}
string Email::getRecipient ( )
{
return recipient ;
}
string Email::getTitle ( )
{
return title ;
}
#pragma once
#include "document.h"
#include <string>
#include <iostream>
using namespace std ;
class File : public Document
{
public:
File ( ) ;
File ( string p ) ;
File operator =( const File & f ) ;
void setPath ( ) ;
string getPath ( ) ;
protected:
string path ;
} ;
#include "file.h"
File::File ( ) : Document ( ) , path ( "No path set" )
{ }
File::File ( string p ) : Document ( ) , path ( p )
{ }
File File::operator =( const File & f )
{
if ( path == f.path )
return *this ;
Document::operator= ( f ) ;
path = f.path ;
return *this ;
}
void File::setPath ( )
{
cout << "Path: " << flush ;
cin >> path ;
}
string File::getPath ( )
{
return path ;
}
#include "document.h"
#include "email.h"
#include "file.h"
int main ( )
{
Document doc ;
Email email ;
File file ;
cout << "Document\n" ;
doc.setText ( ) ;
cout << "\nEmail\n" ;
email.setData ( ) ;
cout << "\nFile\n" << endl ;
file.setPath ( ) ;
cout << "\nDocument:\n" ;
cout << doc.getText ( ) ;
cout << "\nEmail\n" ;
cout << "To: \t" << email.getSender ( ) << endl ;
cout << "From: \t" << email.getRecipient ( ) << endl ;
cout << "Subject: \t" << email.getTitle ( ) << endl ;
cout << email.getText ( ) << endl ;
cout << "\n\n-- Done --\n\n" ;
return 0 ;
}
Sample Output:
Document
Body:
this is a test
Email
From: me
To: you
Subject: this is a test
Body:
File
Path:
BUT, sample output:
Document
Body:
This is a test.
Email
From: me
To: you
Subject: subject
Body:
Another test
File
Path: blah/blah/blah
Document:
This is a test.
Email
To: me
From: you
Subject: subject
Another test
-- Done --
Press any key to continue . . .