Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, First time using Chegg, I need help on a program i am trying to write. It

ID: 3557144 • Letter: H

Question

Hello, First time using Chegg,

I need help on a program i am trying to write. It is an Address book type of program. Currently i am stuck trying to get an input and output file stream. Here are the requirements

It is fine by me if the input/ouput do not meet all of the requirements but it is important that it Reads/Wrties to a text file.

This is my first computer language so if there are any mistakes please let me know so that i can learn from them. Here is my code thus far.

Thank you.

/**
CS-11 Asn 11
store.cpp
Purpose: Add iostream and ofstream into the source code

@author Kent Carlson
@version 1.0 4-17-14
*/

#include <iostream>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <fstream>
using namespace std;

class AddressBook{

public :
AddressBook()
{
count = 0;
}

void AddEntry();
void DisplayAll();
void DisplayEntry(int i); // Displays one entry   
void SearchEntry();

int MainMenu();

struct Entry_Struct
{
char firstName[ 15 ] ;
char lastName[ 15 ] ;
char birthday[ 15 ] ;
char phone[ 15 ] ;
char email[ 15 ] ;
};

Entry_Struct entries[100];
unsigned int count;
};



AddressBook my_book;

int MainMenu()
{
int num;
bool bQuit = false;

// Put all your code into a while loop.   
while(bQuit == false)
{

cout << "+-------------------------------------+" << endl;
cout << "| Address Book Menu |" << endl;
cout << "| |" << endl;
cout << "| 1- Add an entry |" << endl;
cout << "| 2- Search for an entry by last name |" << endl;
cout << "| 3- Display all entries |" << endl;
cout << "| 4- Exit |" << endl;
cout << "| |" << endl;
cout << "+-------------------------------------+" << endl;

cout << endl;
cout << "Please enter a number for one of the above options: ";
cin >> num;
cout << endl;

if (num == 1)
my_book.AddEntry();
else if (num == 2)
my_book.SearchEntry();
else if (num == 3)
my_book.DisplayAll();
else if (num == 4)
bQuit = true;
else
cout << "Invalid choice. Please try again" << endl;

cout << endl;
}

return 0;
}

int main() {
   MainMenu();          
   return 0;
}

void AddressBook::AddEntry()
{
cout << "Entry number " << (count + 1) << " : " << endl;

cout << "Enter First Name: ";
cin >> entries[count].firstName;

cout << "Enter Last Name: ";
cin >> entries[count].lastName;

cout << "Enter Date of Birth: ";
cin >> entries[count].birthday;

cout << "Enter Phone Number: ";
cin >> entries[count].phone;

cout << "Enter Email: ";
cin >> entries[count].email;

++count; // tally total entry count   
}

void AddressBook::DisplayEntry(int i)
{
cout << "Entry[" << i + 1 << "] : " << endl; // states # of entry   
cout << "First name : " << entries[i].firstName << endl;
cout << "Last name : " << entries[i].lastName << endl;
cout << "Date of birth : " << entries[i].birthday << endl;
cout << "Phone number : " << entries[i].phone << endl;
cout << "Email: " << entries[i].email << endl;
}

void AddressBook::DisplayAll()
{
cout << "Number of entries : " << count << endl;

for(unsigned i = 0; i < count; ++i)
DisplayEntry(i);
}

void AddressBook::SearchEntry()
{
char lastname[32];
cout << "Enter last name : ";
cin >> lastname;

for(unsigned i = 0; i < count;++i)
{
if(strcmp(lastname, entries[i].lastName) == 0)
{
cout << "Found ";
DisplayEntry(i);
cout << endl;
}
}
}

Explanation / Answer

Sequential File Problem
I

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote