[Solved] Midterm exam Part 2: Programming

$25

File Name: Midterm_exam_Part_2:_Programming.zip
File Size: 301.44 KB

SKU: [Solved] Midterm exam Part 2: Programming Category: Tag:
5/5 - (1 vote)

Timing and general instructions

You have 1 hour to complete the programming part of the midterm exam. This is a closed notes exam so you should not open any website other than the Titanium midterm exam page. Do not communicate with your classmates or look at their screens. Direct all your questions to the instructor or lab assistant only.

You are allowed to view your own study guide and use paper for scratch work that will be provided for you.

You are free to use any editor and the command line on Tuffix to write, compile, and test your program. The instructors will use clang++ to check your programs so make sure your code works with it.

You are expected to have used the programming environment during our lab sessions so instructors and lab assistants will not answer questions regarding interpretting syntax errors or debugging code.

Problem and points

There are three programming problems that you need to complete.

  1. Discounted sum (5 points)
  2. Radio (5 points)
  3. Student info (5 points)

Submission

Your answers will be submitted through GitHub. You can push your code as many times as you want before the end of the midterm exam. We will check the last version that you pushed.

When you are done, verify you have pushed your code properly on GitHub. Simply refresh your GitHub repo and click on the individual files to see if they have been changed.

On Titanium, click on the Add submission button in the midterms page. Provide the URL for your GitHub repo containing the midterm exam and click on Save changes. Finally click on Submit assignment.

Before leaving the room, please approach the instructor who will verify that you submitted your exam properly. Also turn in your scratch paper and study guide to the instructor.

Discounted prices

Create a function called discounted_sum. This function receives two parameters, an array that contains item prices, and the total number of items inside that array.

The function will go through each price in the array and compute the total price. However, whenever a price is over $50.00, that price will get a 5% discount. Take note, it is only that item that gets the discount, not the total amount.

The function should return the total price.

You need to create the function prototype in discount.hpp and the function implementation in discount.cpp. Modify the main function inside main.cpp to call your function. More detailed instructions are found inside main.cpp.

Even though the main function uses an array of five elements, your discounted_sum function should be able to handle any number of elements.

Code evaluation

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

cd midterm

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 discount.cpp and 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 discount.cpp -o main

./main

Radio

Create a class called Radio. It has three data members.

  • volume: indicates how loud the radio is (for example, 1 is lowest and 10 is highest)
  • station: refers to a radio station (for example, 103.5)
  • is_on: which refers to whether the radio is on or off

Create accessors and mutators for all the data members.

In the main function, create a Radio object, change its volume to 3, change its station to 98.3, and turn the radio on. Use the objects accessors to display information about the radio on the screen. More detailed instructions are found inside main.cpp.

You need to create the Radio class inside radio.hpp and modify the main function inside main.cpp. You do not need to create other files aside from these two.

Code evaluation

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

cd midterm

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

cd prob02

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 prob02, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob03 for example.

cd ..cd prob03

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code saved 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

Student Info

The program in main.cpp should read the data inside students.txt and display it on screen. However, the programmer who built the code suddenly had to leave and it is up to you to complete their program. Find and fix the errors in main.cpp.

Take note of how the data is organized inside students.txt. It will always contain a name followed by a CWID. The name can contain an arbitrary number of strings. We will not know before-hand the number of students in the file, so your program should handle files with any number of students.

After making your modifications, the output should match the following format exactly, including spaces and newlines:

Name: John DoeCWID: 8194487Name: Jane SmithCWID: 8173258Name: Edith Summers LeeCWID: 8165834

You only need to modify main.cpp.

Code evaluation

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

cd midterm

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

cd prob03

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 prob03, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob01 for example.

cd ..cd prob01

Use the clang++ command to compile your code and the ./ command to run it. The sample code below shows how you would compile code saved inmain.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

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Midterm exam Part 2: Programming
$25