Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to

image text in transcribedimage text in transcribedimage text in transcribed

You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an output file. Assume that the user types any character when prompted to select a menu option. If an input file cannot be opened, the program prints an error message and reprints the menu as shown in the sample solution. The output file is assumed to open correctly. In addition to your main function, Your solution must include the following non-trivial functions: 1. A function to print out the menu - a void function. Output statements only 2. A function that returns any integer value entered by the user 3. A function to open an input filet - may want to use as a Boolean value returning function 4. A function to open an output file 5. A function for compression? 6. A function for decompression? 'These functions require 1 reference parameter - an input file stream or output file stream variable. These functions must be used to open the files. 2These functions require 2 reference parameters - an input and an output file stream variable Example The compression scheme is illustrated below. Decompressed Text Compressed Text Observations abbccc 1a2b3c2 la 1 copy of a, 2b + 2 copies of b,... 4d1 2 2 copies of and so on dddd Note #1: represents a newline character Note #2: You should be able to take a file compressed by your program and use your program to decompress it and recover the original file. In other words, if Option 1 compresses X to produce the file Y, then Option 2 should decompress Y to produce a file Z that is identical to X. 0 . Global variables are not allowed. Using global variables will result in a score of 0 on this assignment. You may only use concepts presented in chapters 1-9 of your textbook. You must use function prototypes and all function definitions go below mainete The program must have at a minimum the six non-trivial functions listed on page 1. The Print Menu Function will have output statements only. It will not read in and return any value ft The function to obtain an integer is to return any integer value. This function will handle the case of invalid character entry only. The menu selection is to be read into an integer variable only, not a character No user defined function can call another user defined function except for the obtain integer function which is allowed to call the print menu function . The following algorithms/Functional Decomposition layout should help with writing your program: Put function prototypes above main Declare variables in main Print the menu (Use a function to print out the menu) Obtain an integer choice (Use a function to obtain an integer) Loop while the choice is not o Note: This part of the algorithm if the choice is compress uses the open file functions outside Open the input file (use a function) of the compress or decompress if the input file stream is in the fail state mode functions. print out an error message - cannot open file The compress and decompress else function calls must use the file Open the output file (use a function) streams as arguments. Compress the input file (use a function) else if decompression selected Open the input file (use a function) if the input file stream is in the fail state mode print out an error message - cannot open file else Open the output file (use a function) Decompress the input file (use a function) else Error message for invalid integer entered Reset the input and output file stream variables using (fileStream represents the name of the file stream used in your program) file Stream.close(); fileStream.clear() Print the menu Obtain integer choice End of loop Output program ending message End of program Function Definitions go after main Functions for opening an input or output file, prompt the user for the filename, read the name, echo print it and then open the file. These functions have one reference parameter the file stream being opened. Write one function for the input file and one for the output file. These functions do not loop on invalid filenames. Write a function that prints the menu

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=24/Why does the market portfolio include all risky assets?

Answered: 1 week ago