in c++, due april 14 Consider a program to enter codes of one to eight character
ID: 651676 • Letter: I
Question
in c++, due april 14
Consider a program to enter codes of one to eight characters along with an associated telephone number and associated notes. A code can represent a person's name, a person's initials, a place, or anything.
By using such a program, we could enter telephone numbers or notes and associate them with some brief code (i.e. string, which hopefully would be easy to remember. We could then retrieve a given telephone number or notes by entering the code. This might be a useful application for a simple cell phone.
Codes are entered as 1 to 8 characters.
Use "e" for enter, "f" for find, "l" to list, "q" to quit.
Command: e Bill
Enter number: 419-536-1234
Enter notes:
Command e JB
Enter number: 510-0114
Enter notes: Charlie's place
Command e Jones
Enter number: 413-257-1234
Enter notes: Karen and Jason
Command: e wm
Enter number: 419-257-1234
Enter notes: Walmart
Command: f JB
-- JB
-- 617-510-0114
-- Charlie's place
Command: f Jane
** No entry with code Jane
Comand: . . .
There is also an "l" command, which will list all entries on thte screen.
For the input to this program, upper and lower case letters are considered equivalent. For example, if a telephone number is entered with the code "Jones", the the codes "JONES", "jones, and "JONes" will all retrieve the telephone number with "Jones".
The entries are to be stored in a file from run to run. When the program begins, the entries in the file are to be read into an array. The array should allow for up to 200 entries. The array does not need to be kept in alphabetical order. You may use a simple sequintial search to retrieve entries.
When the program is exited, the entries should be stored back in a file for use when the program is run again.
Required Program Characteristics: The assignment is to write a program that incorporates the above features. The entries in the phonebook are to be represnted with a simple class:
Class Entry {
public:
string name, number, notes;
};
Use an array to store the entries. THe array should allow for up to 200 entries.
entry entrylist[200];
use a function to read the entries into the program from a file, and a function to store the entries back into the file when the program is exited.
void readPhoneBook ()
void storePhoneBook()
Also, use a function to list all contacts:
void listAllEntries ()
i have so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct contact{
string name, number, notes;
};
ofstream output("c:\phonedata\contactlist.txt");
int rec_num = 0;
int num_entries = 0;
string toupper (string S){
for(size_t i=0; i < S.length(); i++)
S[i] = toupper(S[i]);
return S;
}
void choice(){
cout << "The avaliable options are ";
cout << "Enter e to enter a new name. ";
cout << "Enter f to find a name. ";
cout << "Enter l to see your contact list. ";
cout << "Enter q to quit the program ";
cout << " ";
}
class Entry{
public:
string name, number, notes;
contact contactlist[100];
};
void listAllcontacts(){
cout << "Name: " << contactlist.name;
}
string notes[40];
int main(){
char command;
char notes[40];
string name, number;
string Filename;
choice();
cout << "Command: ";
cin >> command;
while (command != 'q'){
switch(command){
case 'e': cin >> name; cout <<"enter number ";
cin >> number; cout <<"enter notes ";
cin.getline(notes,40); break;
case 'f': cin >> name; find ;name(name); break;
case 'l': listAllcontacts(); break;
}
}
if (command == 'q')
cout << "Good bye";
return 0;
}
Explanation / Answer
I suspect the matter is that you are making an attempt to brute-force your approach through the assignment by thinking strictly in terms of the code. Your overall structure in main() is usually fine, thus you have got thought through the very best level. currently simply break down every step into what it must do. as an example, adding a replacement contact includes prompting the user, acceptive input (both of that you have done), making a replacement contact object victimization that input, and adding the contact object into the list. Break every step into additional sub-steps before you are concerned concerning writing the code.
You have a contact struct, thus you do not additionally would like associate Entry category. Instead you wish a category to manage your list of contacts, perhaps you wish to decision it ContactList. What members will it would like? What methods? (Hint: it does not need a reputation, range and notes fields.)
Once you have got the code operating, there ar different optimizations you'll build. as an example, you'll embody obtaining the specified command from the user into your choice() function:
char choice() {
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.