1. Write a C++ program that includes a function to calculate the discount applicable on the price of an item. Your funct

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1. Write a C++ program that includes a function to calculate the discount applicable on the price of an item. Your funct

Post by answerhappygod »

1.
Write a C++ program that includes a function to calculate thediscount applicable onthe price of an item. Your function should have three arguments:the price as areference parameter to a double, the discount as a double value,and a bool toindicate if the discount is calculated as a percentage or a fixedamount. Call theparameter to indicate whether the discount is a fixed amount, or apercentage, fixed.When fixed is true, it will indicate that the discount is a fixedamount and when it isfalse, the discount is a percentage. Your function should calculatethe discount andmodify the price of the item accordingly. Your function should check that the discount is not negative andthat the price doesnot drop to zero or below zero after applying the discount. Use theassert() functionto ensure that the discount is not negative and that the price doesnot drop to zero orbelow zero once the discount is applied. Test you program with the following input, and submit the outputfor all the cases: 235.97 7.35 false5430.55 120.00 true856.00 -12.5 false 120.00 130.00 true
NB: Note that you are expected to use the assert macro in thisquestion.
2.
Write a program to help new parents find a name for their baby.The fileBabyNames.dat contains a list of the most popular names for boysand girls, rankedaccording to their popularity.
The user should be able to choose whether to look for boys’names or girls’ namesand to specify which letter of the alphabet the names should beginwith. E.g. I maywant to look for girls’ names starting with an ‘E’. Your programshould copy the namesthat satisfy the user’s criteria (girls’ names starting with an ‘E’in my example) toanother file and include the ranking allocated to thename. E.g. if BabyNames.dat contains the following data showingthat James is the mostpopular boys’ name and Ellen the most popular girls’ name, withMichael and Nazeerain the 10th place:
1 James Ellen2 Peter Eleanor3 Rodger Mary4 John Elise5 Mpho Anne6 Molefe Ella7 Zaheer Petunia8 Charles Eugenie9 Tabang Charlotte10 Michael Nazeera The output file should look as follows, showing all the namesstarting with an ‘E’ andtheir rank:1 Ellen2 Eleanor4 Elise6 Ella8 Eugenie NB: First plan your program on paper (using your computationalthinking to do so).You have to submit your plan for your program as well as the actualprogram code, input and output. Planning your program can take the form ofa flowchart, pseudocode, or notes to guide you in the development of theprogram.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply