Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ELET 2300-03 Homework No. 7 Dr. F. Attarzadeh 80 Points Due 04/13/2017 04/04/201

ID: 3817109 • Letter: E

Question

ELET 2300-03 Homework No. 7 Dr. F. Attarzadeh
80 Points Due 04/13/2017 04/04/2017
It is very important that you read the notes at the end of each assignment for this and all other assignments.
Make sure that you read related lessons, slides, the notes, and the sample programs. Study the exercises,
and study program examples in the book. These are all prerequisites for better understanding of the
classes, objects, and messages.
This assignment covers classes, and strings (refer to chapters 10, 11, 12, and 14 in the assigned text and the
related sample programs and the notes discussed in the class). Enough flexibility are provided for you to
apply your knowledge of the basic C++ programing to develop a solution with enough information and
documentation as needed for this assignment.
Develop a model of the problem you are developing. This is different from the flowcharting you have been
doing throughout the semester. Make sure the model reflects the problem statement. You then need to
develop a C++ program to solve the problem stated by you.
Define a class Name with appropriate data member(s) and member functions (at least constructors and a
destructor for each class.)
Define the class First derived from the class Name that will create your first name with appropriate data
member(s) and member functions (at least constructors and destructor for each class.)
Define the class Last derived from the class Name that will create your last name with appropriate data
member(s) and member functions (at least constructors and destructor for each class.)
You will create an object of the class First and an object of the class Last using the default constructors
and constructors with arguments.
The default constructors initialize the two objects F1 and L1. An overloaded constructors will obtain the
first name and the last name from the keyboard and create objects F2 and L2.
The program will then display your full name using the function displayName() to display your full name
in the format shown below.
Firstname Lastname
Once the first name and last name are displayed, the program ends.
Other member functions for the classes are defined by the programmer and as a minimum will include
constructors, destructors, accessor, and mutating functions. User-defined functions will be used as needed
to solve your problem.
This program leaves out a few options for you to select

Notes:(please read very carefully)
Grading:
Program model 10 points
Choice of data selected 5 points
Documentation 10 points – problem statement, class, member functions, main(), etc.
Proper development of classes,
and member functions 35 points
Program completeness 10 points, this includes program correctness, efficient
programming, using right constructs for the solution, and
proper use of coding as emphasized in class
Sample correct outputs 10 points
Notes:(please read very carefully)
1. Make sure your files are VIRUS FREE! (A grade of 0 will be given for infected files). Use Technology lab PCs for the test.
2. Comment your program.
3. Use meaningful prompts.
3a. You need to review “how to submit your homework” document. Incomplete submissions will not be graded.
4. Provide a brief description of the problem being solved.
5. Be sure to include a header file at the beginning of your program as shown in the course syllabus.
6. NO global declarations allowed, except for the function prototypes and class declarations.
7. Use classes, member functions, and strings.
8. Full member -function prototyping is required. Member functions must have their purposes fully explained.
8A. No member function should be defined within a class (i.e., no body of a member function should be seen inside
any of the classes you are defining)
9. Make sure to use constructors and destructors for the classes. A class may have more than one constructor.
10. Parameter passing to the user-defined functions, the class member functions and the return types will be
specified by you. The function prototypes will clearly show the formal parameters and the return values.
11. Use data types as specified in the member function prototypes. All class data members will be in the private
access region of the class.
12. On the due date, submit your H7 containing the components of the program specified in the guidelines. Create a Word
file that contains the header, the flowchart, the list of your .cpp file, and the sample runs of the program. Name this file
H7NAME.docx. The source file for H7NAME.cpp and the Visio 2013 file H7NAME.vsdx will be uploaded as well. Unrelated files
should not be present when you upload them to the Blackboard. Homework must be uploaded to Blackboard before 9PM of
the due date. NAME is your last name.
13. Use Microsoft Visual Studio Enterprise 2015 compiler using default compiler settings.
14. Use Microsoft Visio 2013 to develop your flowchart.
15. Illegal inputs must be handled properly without terminating the program.
16. Adherence to the ANSI C++ required.
17. Do not use <stdio.h> and <conio.h> in this assignment and all other assignments.
18. Do not use any #define in your program until the time that is required for class declaration header files.
19. No goto statements allowed in any program that you develop in this course.
20. Non-compliance with these notes will cost you points.
21. No collaboration on this assignment and all other assignments allowed. If you violate this policy, your grade for the course
will be F.
22. You need to show us your program model/flowchart before we can help you with your code.
23. When copying and pasting code into a Word document, please use the Courier New font with a font size no more than 10.
24. Late homework will not be accepted.
25. When copying and pasting code into a Word document, please use the Courier New font with a font size no more than 10.

Explanation / Answer

PROGRAM CODE:

#include <iostream>
using namespace std;

//base class - name
class Name
{
private:
string name;
public:
Name();
Name(string newname);
~Name();
string getName();
void setName(string newname);
void print();
};

//class First - derived class
class First: public Name
{
public:
First();
First(string newname);
~First();
  
};

//class Last - derived class
class Last: public Name
{
public:
Last();
Last(string newname);
~Last();
};

//Default constructor for Name
Name::Name()
{
name = "null";
}
//constructor with a value for name
Name::Name(string newname)
{
name = newname;
}
//destructor for the class
Name::~Name()
{
//does the default action
}
//retuns the name
string Name::getName()
{
return name;
}
//sets a new name
void Name::setName(string newname)
{
name = newname;
}
//prinst the name on screen
void Name::print()
{
cout<<name;
}

//constructor for First - calls the base class constructor
First::First():Name(){}
//Parameterized constructor - calls the base class constructor
First::First(string newname):Name(newname){}
//destructor for the class
First::~First(){}

//constructor for Last - calls the base class constructor
Last::Last():Name(){}
//Parameterized constructor - calls the base class constructor
Last::Last(string newname):Name(newname){}
//destructor for the class
Last::~Last(){}

void displayName(First f, Last l)
{
   cout<<endl;
   f.print();
   cout<<" ";
   l.print();
}

int main() {
//creating objects without initializing
First F1;
Last L1;
displayName(F1, L1);
cout<<endl;
//creating objects with name
string fname, lname;
cout<<"Enter the first name: ";
cin>>fname;
cout<<" Enter the last name: ";
cin>>lname;
First F2(fname);
Last L2(lname);
displayName(F2, L2);
cout<<endl;
return 0;
}

OUTPUT: