
Concept explainers
C++
Assignment 1
This program will store structure data in a file called Customers.dat.
For this assignment, create a menu with the following tasks:
1. Add DataX
. Exit Program
This menu needs to display "Invalid choice" if '1' or 'X' is not the given choice. The menu should redisplay options until item 'X' is selected.
Prior to this menu loop, the program needs to create the Customers.dat file if it does not existThe file "Customers.dat" must be opened in Binary mode.
The file is opened for processing prior to the menu.
This program may be written to automatically reset an existing Customers.dat file if it already exists.
For option '1', prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine;
const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;
struct Customers {
long customerNumber;
char name[NAME_SIZE];
char streetAddress_1[STREET_SIZE];
char streetAddress_2[STREET_SIZE];
char city[CITY_SIZE];
char state[STATE_CODE_SIZE];
int zipCode;
char isDeleted;
char newLine;
};
Always set the item isDeleted to 'N' and newline to '\n'. The item newLine is a convenient item that is there to assist in viewing the contents of the file using "type filename" in the cmd window.
The item customerNumber should start at 0 and increase by 1 for every record written. This data item is not viewable in the file via notepad because it is stored in a binary format.
Notepad will show the binary chars and will not line up the data as expected. You may see some odd characters after the expected data for the character arrays. That is normal for C/C++.
Once the data in the structure is loaded, append the structure to the file "Customers.dat" and return to the menu.
For option 'X':
Close the data file
display "Done!"
Let the program terminate.
Assignment 2:
Copy Assignment 1 to Assignment 2. Relabel this assignment to be Assignment 2. If there were comments made regarding the grading of Assignment 1, apply those changes to assignment 2.
-
Modify this program to open the file "Customers.dat" so that all data can be read, and data written or appended to this file.
-
Add an option 2 and 3 to the menu so that the menu appears as below:Menu options '2' and '3' should now be considered a valid choice.
- 1. Add Data
2. Update Data
3. Display all data
X. Exit Program
- 1. Add Data
-
Create a method called "getLargestCustomerNumber" and call it after the "Customers.dat" file has been opened. Read all the existing customerNumbers and determine the largest customerNumber. Use this number as the base when adding new customer data.
-
The program should be able to start multiple times and add data with increasing customerNumbers. There should be no duplicated customer numbers.
-
Menu Option 2 should do the following tasks
-
-
Prompt for a customer number to change.
-
Enter the address information ( Street 1 & 2, City , State and Zipcode)
-
Find the record for the customer number and replace the address information.
-
-
Menu Option 3 should do the following tasks
-
-
Reset the file pointer to the beginning of the file.
-
For each record in the file, display the customer number, customer name and all address information. The items isDeleted and newLine are not to be displayed.
-

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

- C++ Add a search command that asks the user for a string and finds the first line that contains that string. The search starts at the first line currently displayed and stops at the end of the file. If the string is found, the line that contains it is displayed at the top. In case the user enters a string X that does not occur in the file, the program should print the error message: ERROR: string "X" was not found. Attached is the first lines of the .txt filearrow_forwardC++ Add a search command that asks the user for a string and finds the first line that contains that string. The search starts at the first line currently displayed and stops at the end of the file. If the string is found, the line that contains it is displayed at the top. In case the user enters a string X that does not occur in the file, the program should print the error message: ERROR: string "X" was not found.arrow_forwardPYTHON!!! The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of 12%. Monthly payments are 5% of the listed purchase price, minus the down payment. Write a program that takes the purchase price as input. The program should display a table, with appropriate headers, of a payment schedule for the lifetime of the loan. Each row of the table should contain the following items: The month number (beginning with 1) The current total balance owed The interest owed for that month The amount of principal owed for that month The payment for that month The balance remaining after payment The amount of interest for a month is equal to balance × rate / 12. The amount of principal for a month is equal to the monthly payment minus the interest owed. An example of the program input and output is shown below: Enter the puchase price: 200 (SEE IMAGE FOR PURCHASE PRICE CHART) Results you should get: Input: 200 Output: Purchase price: 200…arrow_forward
- Open the project or solution named mpg in this folder: ex_starts\ch07_ex1_mpg Review the code and run the program to refresh your memory on how it works. Notice that, unlike the program in this chapter, this program lets the user perform more than one calculation, it stores the values the user enters in a text file, and it displays the total miles, total gallons, and average miles per gallon when the program starts and after each entry. Add a function that calculates the miles per gallon Define a function named calculate_mpg() before the main() function that calculates the miles per gallon. This function should accept two double values for the miles and gallons, round the result to two decimal places, and return the result as a double type. Modify the code in the main() function so it uses the calculate_mpg() function. Note that the miles per gallon is calculated in three different places. Move the definition for the calculate_mpg() function after the main() function. When you run…arrow_forward// This pseudocode should create a list that describes annual profit // statistics for a retail store. Input records contain a department // name (for example, ìCosmeticsî) and profits for each quarter for // the last two years. The program should determine whether // the profit is higher, lower, or the same // for this full year compared to the last full year. start Declarations string department num salesQuarter1ThisYear num salesQuarter2ThisYear num salesQuarter3ThisYear num salesQuarter3ThisYear num salesQuarter1LastYear num salesQuarter2LastYear num salesQuarter3ThisYear num salesQuarter4LastYear num totalThisYear num totalLastYear string status num QUIT = "ZZZZ" housekeeping() while department <> QUIT compareProfit() endwhile finishUp() stop housekeeping()DEBUG04-02.txt output "Enter department name or ", QUIT, " to quit " input dept return compareProfit()…arrow_forward5. Charge Account Validation If you have downloaded the source code from the Computer Science Portal you will find a file named charge_accounts.txt in the Chapter 07 folder. This file has a list of a com- pany's valid charge account numbers. Each account number is a seven-digit number, such as 5658845. Programming Exercises 403 program Write a program that reads the contents of the file into a list. The program should then ask the user to enter a charge account number. The program should determine whether the number is valid by searching for it in the list. If the number is in the list, the should display a message indicating the number is valid. If the number is not in the list, the program should display a message indicating the number is invalid. (You can access thearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





