Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can not solve the problem below

Write a program that lets users keep track of the last time they talked to each of their friends.
Users should be able to add new friends (as many as they want!) and store the number of days ago that they last talked to each friend. Let users update this value (but dont let them put in bogus numbers like negative values). Make it possible to display the list sorted by the names of the friends of by how recently it was since they talked to each friend.

I have tried a little but i know it is rubbish

[edit]Code block added - OriginalGriff[/edit]

What I have tried:

C++
include <iostream>
#include <string>

using namespace std;


int main()
{
 int size;
 int array_[size];
 int*p_array;
 p_array=&array_[0];


 cout << "number of friends" << endl;
 cin >> size;

 for(int i=0;i<size;i++)>
 { string name_i;
     string *p_name_i;
 *p_name_i= name_i;

     cout << "name of friend " << i;
     cin >> name_i ;



     cout << "For Name :- " << *p_name_i   << endl;

     cin >> *(p_array+i) ;




     cout << *p_name_i ;

     cout << *(p_array+i);

 }

}
Posted
Updated 7-Jun-16 11:12am
v3
Comments
Member 12566145 7-Jun-16 5:02am    
If Anyone can solve the question it would be a great Help

Thanks in Advance

You should do your homework yourself. Please ask here only specific questions.
 
Share this answer
 
This is your homework, so we aren't going to do it for you - that would defeat the point!
It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

And that code isn't very good, mostly because you haven't tried to do what the question asks you to.
Start at the beginning: read the question carefully. The first thing it says is that users should be able to add new friends. The second is that it's "as many as they want" - so your fixed size array is not going to work, even if you did give it a size, which you haven't.

This needs pointers, as you said in the title. So create a struct for each friend, and write a function which creates a friend (using malloc) and lets the user fill in the details. The function then returns the friend and the main function then adds it to a list.
Get the function working first, creating a freind structure and populating it with user input. Then write a function to print information from a friend structure. Test them both thoroughly. Then start working on the list part.
Break it all down into smaller pieces and it should be a lot easier to do.
 
Share this answer
 
I have no intention of solving this as it homework you need to learn it. I will however give you a good start point
// FORWARD DECLARATION
typedef FRIEND* PFRIEND;

// RECORD THAT DESCRIBES EACH CONVERSATION ... HINT SINGLE LINKED LIST
typedef struct ConversationRecord {
	PFRIEND party1;									// Party talking to
	long talkTimeInSeconds;							// Conversation length
	long daysSinceTalk;								// days since spoken too
	struct ConversationRecord* nextConversation;	// Ptr to next conversation
} CONVERSATIONS;

// RECORD THAT DESCRIBES EACH FRIEND .. HINT SINGLE LINKED LIST
typedef struct friendRecord {
	char* personsName;								// Persons name
	CONVERSATIONS* lastConversation;				// Last conversation record
	PFRIEND nextFriend;								// Pointer to next friend
} FRIEND;

// Global list of all friends
PFRIEND friendList = 0;

Now start by creating the list of friends into friendlist.

It's all single linked lists, you may later decide to change to double linked list for speed. Now read up on lists and do the homework.
 
Share this answer
 
Quote:
Users should be able to add new friends (as many as they want!) and store the number of days ago that they last talked to each friend. Let users update this value (but don't let them put in bogus numbers like negative values).
If the data is to be stored in a database, it is a bad idea to store the number of days since last talk, because tomorrow they all will be wrong.
The right solution is to store the date of last talk instead.
So intead of storing user input, just subtract from current date and store the result which is date of last talk.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900