Lab exercise 5 Problems Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (5 votes)
  1. Write C++ programs
  2. Compile C++ programs
  3. Implement programs that read and write to files

Instructions

Answer the programming problems sequentially (i.e., answer prob01 before prob02). If you have questions let your instructor or the lab assistant know. You can also consult your classmates.

When you answer two programming problems correctly, let your instructor know and wait for further instruction.

Lab exercise guide

Here’s a link to the Lab exercise guide in case you need to review the lab exercise objectives, grading scheme, or evaluation process.

Phonebook

This program is used to create a phonebook for storing contact information into a text file.

The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive).

After the user types Done, store all contact information into the file name they provided at the beginning of the program. If the user does not add any contacts, then the file should be empty.

Please see the sample output below to guide the design of your program.

Sample Output:

Please provide the file name for your phone book: contacts.txt

Contact 1:
Please provide the name: Elsie Simon
Please provide their number: (202)555-0115

Contact 2:
Please provide the name: Kaisha Cope
Please provide their number: 5455689016

Contact 3:
Please provide the name: Sultan Vargas
Please provide their number: 371-998-4166

Contact 4:
Please provide the name: Done

Saving phonebook into contacts.txt

Done!

Submission checklist

  1. Compiled and ran the driver (main).
  2. Manually checked for compilation and logical errors.
  3. Ensured no errors on the unit test (make test).
  4. Followed advice from the stylechecker (make stylecheck).
  5. Followed advice from the formatchecker to improve code readbility (make formatcheck).

Code evaluation

Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy and you are currently in /home/student you can issue the following commands

cd labex02-tuffy

You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.

cd prob01

When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02 for example.

cd ..
cd prob02

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code save in main.cpp and into the executable file main. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.

clang++ -std=c++17 main.cpp -o main
./main

You can run one, two, or all the commands below to test your code, stylecheck your code’s design, or formatcheck your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.

make test
make stylecheck
make formatcheck

A faster way of running all these tests uses the all parameter.

make all

 

Phonebook display

This program loads contact information stored in a text file and displays it on the screen.

The program asks the user to provide the filename of a phonebook file. It will then load all of the names and numbers stored in the file and display them on the screen.

We assume that the file is stored using the correct format wherein for each contact, there is always a name followed by their phone number. Below is an example of a possible phonebook file.

Sample phonebook file (phonebook.txt):

Shanay Wickens
7205972770
Harlee Collins
3328206140
Addison Ryan
7917471622

Please see the sample output below assuming it loaded the phonebook file shown above to guide the design of your program. In case there are no contacts, inform the user that there were no contacts stored in the file. If the file does not exist, inform the user that the phonebook file is missing.

Sample Output:

Please provide the file name for your phone book: phonebook.txt

Contact 1:
Name: Shanay Wickens
Number: 7205972770

Contact 2:
Name: Harlee Collins
Number: 3328206140

Contact 3:
Name: Addison Ryan
Number: 7917471622

Empty phonebook sample Output:

Please provide the file name for your phone book: phonebook.txt

Phone book does not contain any contacts!

Missing phonebook file sample Output:

Please provide the file name for your phone book: phonebookszz.txt

Invalid phonebook file!

Submission checklist

  1. Compiled and ran the driver (main).
  2. Manually checked for compilation and logical errors.
  3. Ensured no errors on the unit test (make test).
  4. Followed advice from the stylechecker (make stylecheck).
  5. Followed advice from the formatchecker to improve code readbility (make formatcheck).

Code evaluation

Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy and you are currently in /home/student you can issue the following commands

cd labex02-tuffy

You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.

cd prob01

When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02 for example.

cd ..
cd prob02

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code save in main.cpp and into the executable file main. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.

clang++ -std=c++17 main.cpp -o main
./main

You can run one, two, or all the commands below to test your code, stylecheck your code’s design, or formatcheck your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.

make test
make stylecheck
make formatcheck

A faster way of running all these tests uses the all parameter.

make all

Donations

This program is used to store donor contributions into a text file.

The program begins by asking the user to provide the number of donors participating in their cause and then the name of the file to store donation information. It will then ask the user to provide the donation amounts for each of the donors. The number of donors and the donation amounts should be stored into the text file with the file name provided by the user.

The program should only store the file if the user indicates that there is at least one donor. Otherwise, the program will not ask for a filename and display an error.

Please see the sample output below to guide the design of your program.

Sample Output:

Please provide the number of donors: 3
Please provide the name of the donations file: donations.txt

Donor 1: $35.00
Donor 2: $500.00
Donor 3: $235.10

Thank you for donating!

Sample Output file:

3
35
500
235.10

Sample invalid input:

Please provide the number of donors: 0
You need to have at least one donor for your cause to save donation information.

Submission checklist

  1. Compiled and ran the driver (main).
  2. Manually checked for compilation and logical errors.
  3. Ensured no errors on the unit test (make test).
  4. Followed advice from the stylechecker (make stylecheck).
  5. Followed advice from the formatchecker to improve code readbility (make formatcheck).

Code evaluation

Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy and you are currently in /home/student you can issue the following commands

cd labex02-tuffy

You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.

cd prob01

When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02 for example.

cd ..
cd prob02

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code save in main.cpp and into the executable file main. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.

clang++ -std=c++17 main.cpp -o main
./main

You can run one, two, or all the commands below to test your code, stylecheck your code’s design, or formatcheck your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.

make test
make stylecheck
make formatcheck

A faster way of running all these tests uses the all parameter.

make all

 

Donations display

This program loads donation information stored in a text file, displays each one on the screen, and displays the total donations.

The program asks the user to provide the filename of a donation file. It will then load all of the donations in the file and display them on the screen. Finally it will display the total of all donations.

A donation file’s first line describes the number of donations listed in the file followed by the donations. Below is an example of a possible donation file.

Sample phonebook file (donations.txt):

4
200
143.23
501.37
396.88

Please see the sample output below assuming it loaded the donation file shown above to guide the design of your program. If the file does not exist, inform the user that the phonebook file is missing.

Sample Output:

Please provide the file name for your donation file: donations.txt

Donation 1: $200.00
Donation 2: $143.23
Donation 3: $501.37
Donation 4: $396.88

Total donation: $1241.48

Missing donation file sample Output:

Please provide the file name for your donation file: donationszz.txt

Invalid donation file!

Submission checklist

  1. Compiled and ran the driver (main).
  2. Manually checked for compilation and logical errors.
  3. Ensured no errors on the unit test (make test).
  4. Followed advice from the stylechecker (make stylecheck).
  5. Followed advice from the formatchecker to improve code readbility (make formatcheck).

Code evaluation

Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy and you are currently in /home/student you can issue the following commands

cd labex02-tuffy

You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.

cd prob01

When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02 for example.

cd ..
cd prob02

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code save in main.cpp and into the executable file main. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.

clang++ -std=c++17 main.cpp -o main
./main

You can run one, two, or all the commands below to test your code, stylecheck your code’s design, or formatcheck your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.

make test
make stylecheck
make formatcheck

A faster way of running all these tests uses the all parameter.

make all

Consolidated report

This program loads a monthly report from a report file and displays the consolidated sales for a given range of months.

First, the program will ask the user to provide the filename of the monthly report file. Then the user will provide the number of months that will be consolidated and displayed. For example, if the user selects 1 then the total sales for each month will be shown. If the user selects 2 then every two months’ total sales will be added and shown. If the user selects 3 then the every three months’ total sales is shown and so on.

The program should only accept values equal to one or greater. Otherwise the program should display an error. If the number of months provided by the user does not perfectly divide the total number of months on the report, then it will just show the ranges that contain enough months. For example, if the user selects 2 and there are only 5 monthly reports, then it will display the total sales for months 1 and 2, and 3 and 4, only.

Below is an example of a possible monthly report file.

Sample monthly report file (report.txt):

999.99
705.67
803.23
400.54

Please see the sample output below assuming it loaded the report file shown above to guide the design of your program. If the file does not exist, inform the user that the report file is missing.

Sample Output – 1 consolidated month:

Please provide the file name for your report file: report.txt
Please provide the number of months to consolidate: 1

Month 1 sales: $999.99
Month 2 sales: $705.67
Month 3 sales: $803.23
Month 4 sales: $400.54

Sample Output – 2 consolidated months:

Please provide the file name for your report file: report.txt
Please provide the number of months to consolidate: 2

Month 1 2 sales: $1705.66
Month 3 4 sales: $1203.77

Sample Output – 3 consolidated months:

Please provide the file name for your report file: report.txt
Please provide the number of months to be consolidated: 3

Month 1 2 3 sales: $2508.89

Missing report file sample Output:

Please provide the file name for your report file: reportszz.txt

Invalid report file!

Submission checklist

  1. Compiled and ran the driver (main).
  2. Manually checked for compilation and logical errors.
  3. Ensured no errors on the unit test (make test).
  4. Followed advice from the stylechecker (make stylecheck).
  5. Followed advice from the formatchecker to improve code readbility (make formatcheck).

Code evaluation

Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy and you are currently in /home/student you can issue the following commands

cd labex02-tuffy

You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.

cd prob01

When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02 for example.

cd ..
cd prob02

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code save in main.cpp and into the executable file main. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.

clang++ -std=c++17 main.cpp -o main
./main

You can run one, two, or all the commands below to test your code, stylecheck your code’s design, or formatcheck your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.

make test
make stylecheck
make formatcheck

A faster way of running all these tests uses the all parameter.

make all
  • Lab_05.zip