Morgan Stanley C++ Homework #2

Overview
Your assignment is to create two seperate classes and test programs. Each of the classes is presented below. In order to finish these assignments, you will need to know what a constructor is, the copy constructor, and a default constructor (a default constructor is a constructor that's called when there are no parameters).

Class #1 - MGTest

As with previous class assignments, please name your class flTest, where fl are your first and last initials. The purpose of the MGTest class is to display the behavior and calling convention of various functions in a class. Your class will have no data members, and no private or protected members, only public function members.

The member functions should do nothing but output some text to indicate what they are doing. For this assignment, you can place the class definition, class functions, and test program, all in one '.cpp' file. When you hand in this assignment, please also hand in the printed output of the program.

Function List
The class should provide the following public member functions:

Constructor
You must write a default constructor, so that it displays the text "I'm in the default constructor".

Copy Constructor
You must write a copy constructor, so that it displays the text "I'm in the copy constructor".

Destructor
You must write a destructor, so that it displays the text "I'm in the destructor".

MGTest& operator=( const MGTest& Src );
You must write an assignment operator. The assignment operator does nothing but display the text "I'm in the assignment operator". This function can simply return(*this) when done.

Data Members
The MGTest class has no data members. It does absolutely nothing, but demonstrate the order in which functions such as constructors and copy constructors are called.

 

Test Program

#include <iostream.h>
//Put the MGTest class here.
void Foo( MGTest T )
{
}
int main()
{
	MGTest A, B, C(B);
	A = B;
	Foo( A );
	return(0);
}

Class #2 - MGString

As with previous class assignments, please name your class flString, where fl are your first and last initials. The purpose of the MGString class is to provide a basic dynamic string management ability. For this homework assignment, you may place all the source code and class definitions in a single '.cpp' file.

Function List
The class should provide the following public member functions:

Constructor
You must write a default constructor, so that it properly initializes the Buffer member with 0.

Copy Constructor
You must write a copy constructor, so that it properly initializes Buffer with a duplicate of it's Source parameter's Buffer.

Destructor
You must write a destructor, so that it releases any memory that Buffer may have aquired during use.

MGString& operator=( const MGString& Src );
You must write an assignment operator. The assignment operator does nothing but display the text "I'm in the assignment operator". This function can simply return(*this) when done.

Data Members
It is strongly recommended that you have 1 data member in the class, a char* called Buffer.

Test Program

#include <iostream.h>
#include <stdlib.h>
#include <string.h>

// Put your MGString class here.

int main()
{
	MGString A, B;
	A.Set( "Put into A and B" );
	B = A;
	
	A.Output();
	cout << endl;
	B.Output();
	cout << endl;
	A.Set( "Now just A" );
	A.Output();
	cout << endl;
	B.Set( "Now just B" );
	B.Output();
	cout << endl;
	return(0);
}