代写C代码 代做C程序 C辅导 C家教

远程写代码 Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

 

Goals

To learn about pointers, dynamic memory allocation and data structures managed by pointers.

Your Assignment

Class Person is defined in these files person.h and person.cpp. Use separate compilation methods we have learned to use the Person class in your hw9.cpp file. Your hw9.cpp will utilize the Person class. Your hw9.cpp will contain the int main() which you will write.

Write a program that gets names as input from the user (Read from the console using cin. You may tell the user to enter a name or q to quit entering names.) , allocates a new Person for each of them and stores the pointer to each of them in a vector  . Then ask the user for the name of the best friend for each of the Person objects. Locate the object matching the friend's name and call a set_best_fiend method to update the best_friend pointer and the popularity counter. Finally, print out all Person objects , listing the name, best friend and popularity counter for each.

Here is a sample run of the program: 

Other instructions

The main difficulty in this program is that you are dealing with pointers to Person objects. You are not directly dealing with Person objects. Keep this in mind as you write your code. Before you access any pointer, make sure it is not NULL. Write if statements as necessary to test for this. A persons popularity goes up if they are someones best friend. If you have a best friend that does not increase YOUR popularity. You need to write all necessary member functions for the class.

What to Turn in.
Upload to ccle the source file hw9.cpp

 

FAQ

Q: Are all names unique? A: Yes. There are no repeated names.

Q: Will everyone have a best friend? A: Yes. Everyone has a best friend.

Q: How should we handle user errors? A: You are the user. You will not make mistakes.

Grading

This assignment is worth 5 extra credit points. Turn in something that works and you get 5 pts.

相关推荐