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

This questions was already put individually but I put it together by me someone

ID: 661984 • Letter: T

Question

This questions was already put individually but I put it together by me someone answer it but in my compiler when I run it the first problem and put the L as it described it goes in an infinite loop of numbers and however the person that did the program it works well. Can someone tell me specificly what to do?On the second problem someone answer it but when I run it it has 58 errors on my dev c++ compiler.

This is the problem I already post, more at the bottom is the answer that someone gave me. I only have a until like 2:00pm or 3:00pm of 5/18/2015 for this and I need to do the Problem analysis and flowcharts.

Write a C++ program, Problem 1. Text Editor using files and strings

In this project, you should write a simple line editor. Keep the entire text on a file, one line in a key Enter. Start the program with entering EDIT file, after which a prompt appears along with the line number. If the letter I is entered with a number n following it, then insert the text to be followed before line n. If I is not followed by a number, then insert the text before the current line. If D is entered with two numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the current line. Do the same with the command L, which stands for listing lines. If A is entered, then append the text to the existing lines. Entry E signifies exit and saving the text in a file. Here is an Example:

EDIT testfile

1>The first line

2>               

3> And another line

4>I3

3> The second line

4> One more line

5> L

1>The first line

2>

3> The second line

4> One more line

5> And another line           // This is now line 5, not 3;

5> D2                               // line 5, since L was issued from line 5;

4> L                                 //line 4, since one line was deleted;

The first line

2> The second line           // this and the following lines

3> One more line              // now have new numbers

4> And another line

4> E

The answer that someone gave me:

//Program for Text editor using files and strings

#include <iostream> //For io operations
#include <fstream> //for files
#include <string.h> //for string functions

using namespace std;

int readAllFile(char *fname) //read method
{
   string line;
   int lineno=0;
   ifstream file(fname); //Open file for reading
   getline(file,line); //reading lne
   while(!file.eof()) //if not end of file repeat loop
   {
       lineno++; //Increment line no
       cout<<lineno<<">"<<line<<endl; //Print line
       getline(file,line); //read next line
   }
   file.close(); //Close file
   return lineno; //return count of line numbers
}

int appendLine(char *fname, int lineno) //Appending file content
{
   char line[50];
   fstream file;
   file.open(fname,fstream::in | fstream::out | fstream::app); //opened file for appending
   cout<<lineno<<">";
   cin>>line; //Input line text
   file<<line<<endl; //Store to file
   file.close(); //Close file
   lineno++; //increment line no
   return lineno; //Return line no
}
  
  
      

int main(int argc, char *argv[])
{
   int lineno=0;
   char choice[3]="K"; //For choice input
   while(choice[0]!='E') //If E pressed exit loop/program
   {
           cout<<" ";
           lineno++; //Increase line no
           cout<<lineno<<">";
           cin>>choice; //Input choice L/E/A etc.,
           if(strcmp(choice,"L")==0) //If choice is L
               lineno=readAllFile(argv[1]); //Call read method
           else if(strcmp(choice,"A")==0) //if choice is A
               lineno=appendLine(argv[1],lineno); //Call append method
                //like this other methods can be implemented and called
   }
}

Problem 2. Movie Database System

Write a C++ program that uses the following structures to store the following data about a Customer:

Name

Address

City, State, and ZIP

Telephone Number

Array of rented movies (Nested Structures)!!!

And the following data about Movie

Title

Year of issue

Duration

The structures should be used to access customer records in a file. The program should have a menu that lets the user perform the following operations:

Create new Customer record

Enter the new record into the file.

Search for a particular customer?s record and display it.

Search for a particular customer?s record and delete it.

Search for a particular customer?s record and change it.

Display the contents of the entire file.

Sort the content of the entire file according to customer name and display it.

Exit

This was the answer that someone gave me when I compiled it has 58 errors:

#include< iostream>

#include <string>

#include <fstream>

using namespace std;

/////Declarations////////////////////////////////////////////////

const int Max_Movie = 500;

const int Movie = 500;

const char FILE_PATH[] = "C:\entry_file.txt";

typedef int INDEX;

typedef int TELEPHONE;

typedef string NAME;

typedef array MOVIELIST[];

typedef string ADDRESS;

typedef string ADDRESS2; //CITY,PIN, ZIP

typedef string TITLE;

typedef string YEAR;

typedef DOUBLE DURATION;

int entryCount = -1;   //-1 means the list is empty

fstream entryFile;

class CustomerEntry

{

public:

        CustomerEntry (NAME name, TELEPHONE telephone, ADDRESS address, ADDRESS2 address2), MOVIELIST[] movielist: name(name), telephone (telephone), ADDRESS (address), ADDRESS2 (address2), MOVIELIST[] (movielist) {}

        void operator = (CustomerEntry *entry)

        {

               name = entry->name;

               telephone = entry-> telephone;

               address = entry-> address;

               address2 = entry-> address2;

               movielist = entry-> movielist;

        }

        NAME name;

        TELEPHONE telephone;

       Address address;

        Address2 address2;

}*entryList[MAX_Movie];

class MovieEntry

{

public:

        MovieEntry (TITLE title, DURATION duration, YEAR year: title (title), duration (duration), year (year) {}

        void operator = (MovieEntry *entry2)

        {

               title = entry2->title;

               duration = entry2-> duration;

               year = entry2-> year;

              

        }

        TITLE title;

DURATION duration;

YEAR year;

}*entry2List[Movie];

/////Function prototypes////////////////////////////////////////

INDEX GetCustomerIdx();        //Gets number of index from user

TELEPHONE GetCustomertelephone();

Address GetCustomerAddress();

Address2 GetCustomerAddress2();

NAME GetCustomerName();        //Gets string of name from user

MOVIELIST GetCustomerMovieList();

DURATION GetMovieDuration();

TITLE GetMovieTitle();

YEAR GetMovieYear();

void DeleteFromTheList(INDEX idx);    //Deletes an item with index of idx

void Delete(); //Called by DeleteFromTheList(INDEX)

void ChangeTelephone();        //Changes the mark field of a record

void SetNewMovieList(INDEX idx, movielist[],);//ChangeTelephone()

void SetNewAddress(INDEX idx, address);

void AddCustomerEntry();       //Adds new item to list

void AddMovieEntry();

void AddToList(NAME name, MARK mark); //Called by AddEntry()

void SortList();       //Does a buble sort on list

void ShowName();       //Shows all names with the same mark

void ShowList();       //Shows all the items in the list

int GetUserChoice();   //Gets numbet of option from user

void LoadDataFromFile();       //Loads data from a file

void SaveDataToFile(); //Saves data to a file

/////////////////////////////////////////////////////////////

INDEX GetCustomerIdx()

{

        cout << "Enter index: ";

        INDEX idx;

        cin >> idx;

        return idx;

}

NAME GetCustomerName()

{

        cout << "Enter name: ";

        NAME name;

        cin >> name;

        return name;

}

TELEPHONE GetCustomerTelephone()

{

        cout << "Enter telephone: ";

        TELEPHONE telephone;

        cin >> telephone;

        return telephone;

}

ADDRESS GetCustomerAddress()

{

        cout << "Enter Address: ";

        ADDRESS address;

        cin >> address;

        return address;

}

ADDRESS2 GetCustomerAddress2()

{

        cout << "Enter City, pin and zip: ";

        ADDRESS address2;

        cin >> address2;

        return address2;

}

MOVIELIST GetCustomerMovieList()

{

cout << "Enter Movielist: ";

        MOVIELIST movielist;

        cin>> movielist;

        return movielist;

}

DURATION GetMovieDuration()

{ cout << "Enter MovieDuration: ";

        DURATION duration;

        cin >> duration;

        return duration;

}

TITLE GetMovieTitle()

{

cout << "Enter Movie Tilte: ";

        TITLE title;

        cin >> title;

        return title;

}

YEAR GetMovieYear()

{

cout << "Enter Movie Year: ";

        YEAR title;

        cin >> year;

        return year;

}

void DeleteFromTheList(INDEX idx)

{

        if(entryCount != idx)

               for(int i = idx; i < entryCount; i++) {

                       entryList[i]->name = entryList[i+1]->name;

                       entryList[i]->telephone = entryList[i+1]-> telephone;

                       entryList[i]->address = entryList[i+1]-> address;

                       entryList[i]->address2 = entryList[i+1]-> address2;

                       entryList[i]->movielist = entryList[i+1]-> movielist;

               }

        delete entryList[entryCount];

}

void Delete()

{

        if(entryCount != -1){

               DeleteFromTheList(GetCustomerIdx());

               entryCount--;

        }

}

void SetNewTelephone (INDEX idx, TELEPHONE telephone)

{

        entryList[idx]->telephone = telephone;

}

void ChangeTelephone ()

{

        SetNewMark(GetCustomerIdx(), GetCustomerTelephone());

}

void AddToCustomerList(NAME name, TELEPHONE telephone)

{

        entryList[entryCount] = new CustomerEntry(name, telephone, address,address2,movielist[]);

}

void AddToMovieList(TITLE title, DURATION duration,YEAR year)

{

        entry2List[entryCount2] = new MovieEntry(title,duration, year);

}

void SortList()

{

        for(int i = 0 ; i< entryCount;i++){

               for(int j = 0 ; j < entryCount;j++)

               {

                       if(entryList[j]->name.compare(entryList[j+1]->name ) == 1)

                       {

                               CustomerEntry temp = *entryList[j+1];

                               *entryList[j+1] = entryList[j];

                               *entryList[j] = temp;

                       }

               }

        }

}

void AddEntry()

{

        entryCount++;

        NAME name = GetCustomerName();

        AddToList(name , GetCustomerTelephone(),GetCustomerAddress(),GetCustomerAddress2(),GetCustomerMovieList());

              

        SortList();

}

void ShowTelephone()

{

        NAME name = GetCustomerName();

        for(int i = 0; i< = entryCount; ++i ) if(entryList[i]->name == name) cout<< i << " " << entryList[i]->telephone<< endl;

}

void ShowName()

{

        MARK mark = GetCustomerMark();

        for(int i = 0; i< = entryCount; ++i ) if(entryList[i]->mark == mark) cout<< i << " " << entryList[i]->name<< endl;

}

void ShowList()

{

        for(int i = 0; i< = entryCount; ++i ) cout << i << " " << entryList[i]->name << " " << entryList[i]->telephone << " " << entryList[i]->address<< " " << entryList[i]->address2<<" " << entryList[i]->movielist[] << endl;

}

void ShowMovieList()

{

        for(int i = 0; i< = entry2Count; ++i ) cout << i << " " << entry2List[i]->title << " " << entry2List[i]->duration << " " << entry2List[i]->year<< endl;

}

int GetUserChoice()

{

        int choice;

        cout << "Enter the option's number and press enter: ";

        cin >> choice;

        return choice;

}

void LoadDataFromFile()

{

        entryFile.open(FILE_PATH,ios_base::in);

        if(entryFile.is_open()){

               cout << "File opened." << endl;

               char temp[100];

               for(entryCount = 0; entryFile >> temp; entryCount++)

               {

                       entryList[entryCount] = new CustomerEntry(temp, 0);

                       entryFile >> entryList[entryCount]->telephone;

entryFile >> entryList[entryCount]->address;

entryFile >> entryList[entryCount]-> address2;

entryFile >> entryList[entryCount]->movielist[];

              

               }

               entryCount--;

               entryFile.close();

               entryFile.clear();

        }

        else{

               entryFile.clear();

               cout << "File not found in " << FILE_PATH << endl;

        }

}

void SaveDataToFile()

{

        entryFile.open(FILE_PATH,ios_base::out);

        if(entryFile.is_open()){

               if(!entryFile.good())

               {

                       cout << "Error writing file." << endl;

               }

               else

                       for(int i =0 ;i<=entryCount;i++)

                       {

                               entryFile << entryList[i]->name<<endl;

                               entryFile << entryList[i]->telephone<< endl;

entryFile << entryList[i]->address<< endl;

entryFile << entryList[i]->address2<< endl;

entryFile << entryList[i]->movielist<< endl;

                       }

               entryFile.close();

        }

}

int main()

{

        LoadDataFromFile();

        int userChoice;

        do{

               cout <<"1: Show List 2: Add Entry 3: Change Telephone 4: Delete 5: Search Name 6: Search Address 7: Save and Exit ";

               cout << "Current number of records: " << entryCount + 1<< endl;

               userChoice = GetUserChoice();

               switch (userChoice) {

                       case 1: ShowCustomerList(); break;

                       case 2: AddEntry(); break;

                       case 3: ChangeAddress(); break;

                       case 4: Delete(); break;

                       case 5: ShowTelephone(); break;

                       case 6: ShowName(); break;

                       case 7:SortList(); break;

                       case 8: ShowMovieList(); break;

                       case 9: break;

               }

        }while(userChoice != 9);

        SaveDataToFile();

        return 0;

}

Explanation / Answer

Complete Program:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int MAX = 100;

struct Movie
{
   string Title;
   int Year;
   int Duration;
};

struct Customer
{
   string Name;
   string Address;
   string City;
   string State;
   int ZIP;
   int Phone;  
   Movie movies[MAX];
   int numOfMovies;
};

void createAndStoreNewCustomer(string filename);
void searchAndDisplay(Customer customers[], int count);
void searchAndDelete(Customer customers[], int &count);
void searchAndUpdate(Customer customers[], int count);
void displayCustomers(Customer customers[], int &count, string filename);
void sortAndDisplayCustomers(Customer customers[], int count);
void readCustomersFromFile(Customer customers[], int &count, string filename);

int main()
{
   string filename = "data.txt";  
   Customer customers[MAX];
   int count = 0;
   int choice;
      
   do
   {
       cout << "------------MENU------------" << endl;
       cout << "1. Create new customer record and enter the new record into the file." << endl;
       cout << "2. Search for a particular customer

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