This is a C++ Advance assigment. This is due in 5 days. Please write out all the
ID: 3678181 • Letter: T
Question
This is a C++ Advance assigment. This is due in 5 days. Please write out all the code completely fully workable in Visual Studio.
1. Create class Person as following
class Person
{
private:
string name;
public:
Person();
virtual void getData();
virtual void print()=0;
void printName();
};
Note that the print() function is pure virtual function. That means you have to implement print() function in derived class
2. Derive class Employee from Person class. And the following private member variables:
A. Salary
B. Title
3. Derive class Student from Person class, Add GPA as private member.
4. Override getData() and print() function in Employee and Student class
5. Write a test program, add 2 functions in the test program:
A. Call_getData() pass Person object by reference or pointer
B. Call_print() pass Person object by reference or pointer
C. Show the use of the virtual functions.
6. Write another test program to show in what case the slicing problem happens and how to fix slicing problem by using pointers
This NEEDS to be done exactly as said above. Thanks.
Explanation / Answer
class Person { public string FirstName { get; set; } public string LastName { get; set; } } class Pet { public string Name { get; set; } public Person Owner { get; set; } } /// /// Simple inner join. /// public static void InnerJoinExample() { Person magnus = new Person { FirstName = "Magnus", LastName = "Hedlund" }; Person terry = new Person { FirstName = "Terry", LastName = "Adams" }; Person charlotte = new Person { FirstName = "Charlotte", LastName = "Weiss" }; Person arlene = new Person { FirstName = "Arlene", LastName = "Huff" }; Person rui = new Person { FirstName = "Rui", LastName = "Raposo" }; Pet barley = new Pet { Name = "Barley", Owner = terry }; Pet boots = new Pet { Name = "Boots", Owner = terry }; Pet whiskers = new Pet { Name = "Whiskers", Owner = charlotte }; Pet bluemoon = new Pet { Name = "Blue Moon", Owner = rui }; Pet daisy = new Pet { Name = "Daisy", Owner = magnus }; // Create two lists. List people = new List { magnus, terry, charlotte, arlene, rui }; List pets = new List { barley, boots, whiskers, bluemoon, daisy }; // Create a collection of person-pet pairs. Each element in the collection // is an anonymous type containing both the person's name and their pet's name. var query = from person in people join pet in pets on person equals pet.Owner select new { OwnerName = person.FirstName, PetName = pet.Name }; foreach (var ownerAndPet in query) { Console.WriteLine(""{0}" is owned by {1}", ownerAndPet.PetName, ownerAndPet.OwnerName); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.