Question: You are given the following C + + main function:Assuming that the program compiles, use a trace table with headings i , term 1 ,

You are given the following C++ main function:Assuming that the program compiles, use a trace table with headings i, term1, term2, term3, nextTerm, and cout to show your working for parts a) and c).a) What is the output of the program if 6 is entered for n ?[5 marks]b) Explain what happens when 3 is entered for n.[2 marks]c) What is the output of the program if lines 26 and 27 were interchanged? The value entered for n is 6.[3 marks]Total Marks: 102.a) Write a C++ program to encode a text message found in a file and save the encoded message to a new file. Your program should prompt the user for the following data input:toReplace: The character in the message to be replaced.replacement: The character to replace toReplace.Your program should perform the following tasks:
Read the message from a file named "message.txt"
Replace all occurrences of toReplace with replacement in the message.
Output the encoded message to a new file named "encodedMessage. txt"
Print to the output screen, the number of characters replaced in the message.
Print to the output screen, the encoded message from "encodedMessage .txt".
[14 marks]
Page 3
b) In a bakery, a fixed percentage of butter is taken from a container each day. Assume that values for B and P already exist, where:
B - is the number of cups of butter in the container at the start of the first day.
P- is the percentage of butter in the container taken out each day.
Write a snippet of C++ code to print the number of the day, the amount taken for that day, and the amount remaining at the end of the day. The output should be terminated when 30 days have been printed or the amount remaining is less than 100 cups, whichever comes first.
For example, if B=1000 and P=10, the output should start as follows:
Day Amount Taken Amount Remaining
\table[[1,100,900],[2,90,810],[3,81,729]]
[6 marks]
Total Marks: 20
You are given the following C + + main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!