Public Group

# I need an idea!!!

This topic is 4085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, Im re-learning the basics of C++ and am learning about references. My problem is that I need something to code that would require me apply the things I learned about references into the program. what I learned about references: - how to return a reference from a function - how to create a reference (obviously :D) - how to pass references to functions - how to create const references If anyone has any ideas for something for me to code to use all these elements please let me know. This is always a problem for me when Im learning something new, I never can think of something good to code to apply what I learned into a program. Thanks for any help! [smile]

##### Share on other sites
Quote:
 Original post by NUCLEAR RABBITIf anyone has any ideas for something for me to code to use all these elements please let me know. This is always a problem for me when Im learning something new, I never can think of something good to code to apply what I learned into a program.

Usually, whatever book you are learning from will have plenty of exercises at the end of each chapter that require you to practice and use the contents of that chapter.

-me

##### Share on other sites
Write a function to swap two values. So that if I say:

int a = 10;
int b = 20;
swap(a,b);
cout << a << " " << b << endl;

it should print:

20 10

Not too hard but I don't know what level your at...

##### Share on other sites
Quote:
 Original post by esuvsWrite a function to swap two values. So that if I say:int a = 10;int b = 20;swap(a,b);cout << a << " " << b << endl;it should print:20 10Not too hard but I don't know what level your at...

well, I came up with a dumb little project just to use what I learned. If anyone wants to check it out, heres the code. Let me know if you see something I should improve on or something I should learn.

// eFriendList// 7/16/07// Allows the user to add, delete, and display a list of their friends (lame)#include <iostream>#include <string>#include <vector>#include <iterator>void AddFriend(std::vector<std::string> & friends);void DeleteFriend(std::vector<std::string> & friends);void DisplayFriends(const std::vector<std::string> & friends);void Pause();void InvalidOption();int Menu();int main(){	system("TITLE eFriendsList");	std::vector<std::string> FriendsList;	bool exit = false;	do	{		switch(Menu())		{		case 1:			AddFriend(FriendsList);			break;		case 2:			DeleteFriend(FriendsList);			break;		case 3:			DisplayFriends(FriendsList);			break;		case 4:			exit = true;			break;		default:			InvalidOption();			system("CLS");		}	}while(exit == false);	return 0;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int Menu(){	int option = 0;	system("CLS");	std::cout << "|--------------------------|\n"			  << "|  Welcome to eFriendList  |\n"			  << "|  ----------------------  |\n"			  << "|                          |\n"			  << "|  1 = Add Friend          |\n"			  << "|  2 = Delete Friend       |\n"			  << "|  3 = Display Friend List |\n"			  << "|  4 = Exit eFriendList    |\n"			  << "|                          |\n"			  << "|--------------------------|\n\n"			  << "Selection: ";	std::cin >> option;	system("CLS");	return (option);}//-----------------------------------------------------------------------------------------void Pause(){	std::cout << "\nPress ENTER to continue.\n";	std::cin.ignore();	std::cin.get();}//-----------------------------------------------------------------------------------------void AddFriend(std::vector<std::string> & friends){	std::string friend_name;	std::cout << "Enter Friend Name: ";	std::cin.ignore();	std::getline(std::cin, friend_name);	friends.push_back(friend_name);	std::cout << "\nFriend Added Successfully.\n\n";	Pause();}//-----------------------------------------------------------------------------------------void DisplayFriends(const std::vector<std::string> & friends){	int counter = 0;	if(!friends.empty())	{		for(std::vector<std::string>::const_iterator cIter = friends.begin(); cIter != friends.end(); cIter++)		{			std::cout << counter << " = " << *cIter << "\n";		}	}	else	{		std::cout << "You have no friends added yet\n";	}	Pause();}//-----------------------------------------------------------------------------------------void DeleteFriend(std::vector<std::string> & friends){	int friend_id;	if(!friends.empty())	{		DisplayFriends(friends);		std::cout << "\nEnter Friend Number to delete friend: ";		std::cin >> friend_id;		friends.erase(friends.begin() + friend_id);		std::cout << "\nDeletion Successful.\n";	}	else	{		std::cout << "You have no friends added yet.\n";	}	Pause();}//-----------------------------------------------------------------------------------------void InvalidOption(){	std::cout << "That is not an option.\n";	Pause();}

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 9
• 9
• 13
• 9
• 33
• ### Forum Statistics

• Total Topics
632592
• Total Posts
3007284

×