100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Samenvatting

Summary COS1512 Assignment 2 2022

Beoordeling
-
Verkocht
-
Pagina's
6
Geüpload op
11-07-2022
Geschreven in
2021/2022

COS1512 Assignment 2 2022 UNIQUE NUMBER: DUE DATE: 4 July 2022 TUTORIAL MATTER: Chapters 4,5, 6, 8 and 9 of the Study Guide Chapters 4 (section 4.6), 5 (section 5.5), 6, 8 and 9 (excluding the optional parts of section 9.2) of Savitch WEIGHT: MARKS: 30% 65 Question 1 (5) Write an overloaded function max that takes either two or three parameters of type double and returns the largest of them. Test your overloaded function in a program with the appropriate function calls and displays on the screen to demonstrate that the overloaded function works. Question 2 (5) Write a C++ program that includes a function to calculate the discount applicable on the price of an item. Your function should have three arguments: the price as a reference parameter to a double, the discount as a double value, and a bool to indicate if the discount is calculated as a percentage or a fixed amount. Call the parameter to indicate whether the discount is a fixed amount, or a percentage, fixed. When fixed is true, it will indicate that the discount is a fixed amount and when it is false, the discount is a percentage. Your function should calculate the discount and modify the price of the item accordingly. Your function should check that the discount is not negative and that the price does not drop to zero or below zero after applying the discount. Use the assert() function to ensure that the discount is not negative and that the price does not drop to ze

Meer zien Lees minder
Instelling
Vak









Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
11 juli 2022
Aantal pagina's
6
Geschreven in
2021/2022
Type
Samenvatting

Onderwerpen

Voorbeeld van de inhoud

COS1512 Assignment 2 2022


UNIQUE NUMBER: 195408
DUE DATE: 4 July 2022

TUTORIAL MATTER: Chapters 4,5, 6, 8 and 9 of the Study Guide
Chapters 4 (section 4.6), 5 (section 5.5), 6, 8 and 9
(excluding the optional parts of section 9.2) of
Savitch

WEIGHT: 30%
MARKS: 65



Question 1 (5)
Write an overloaded function max that takes either two or three parameters of type
double and returns the largest of them. Test your overloaded function in a program
with the appropriate function calls and displays on the screen to demonstrate that the
overloaded function works.


Question 2 (5)
Write a C++ program that includes a function to calculate the discount applicable on
the price of an item. Your function should have three arguments: the price as a
reference parameter to a double, the discount as a double value, and a bool to
indicate if the discount is calculated as a percentage or a fixed amount. Call the
parameter to indicate whether the discount is a fixed amount, or a percentage, fixed.
When fixed is true, it will indicate that the discount is a fixed amount and when it is
false, the discount is a percentage. Your function should calculate the discount and
modify the price of the item accordingly.
Your function should check that the discount is not negative and that the price does
not drop to zero or below zero after applying the discount. Use the assert() function
to ensure that the discount is not negative and that the price does not drop to zero or
below zero once the discount is applied.
Test you program with the following input, and submit the output for all the cases:
235.97 7.35 false

5430.55 120.00 true

856.00 -12.5 false

120.00 130.00 true

, NB: Note that you are expected to use the assert macro in this question.



Question 3 (10)
Write a program to help new parents find a name for their baby. The file
BabyNames.dat contains a list of the most popular names for boys and girls, ranked
according to their popularity.

The user should be able to choose whether to look for boys’ names or girls’ names
and to specify which letter of the alphabet the names should begin with. E.g. I may
want to look for girls’ names starting with an ‘E’. Your program should copy the names
that satisfy the user’s criteria (girls’ names starting with an ‘E’ in my example) to
another file and include the ranking allocated to the name.

E.g. if BabyNames.dat contains the following data showing that James is the most
popular boys’ name and Ellen the most popular girls’ name, with Michael and Nazeera
in the 10th place:
1 James Ellen
2 Peter Eleanor
3 Rodger Mary
4 John Elise
5 Mpho Anne
6 Molefe Ella
7 Zaheer Petunia
8 Charles Eugenie
9 Tabang Charlotte
10 Michael Nazeera
The output file should look as follows, showing all the names starting with an ‘E’ and
their rank:
1 Ellen
2 Eleanor
4 Elise
6 Ella
8 Eugenie

NB: First plan your program on paper (using your computational thinking to do so).
You have to submit your plan for your program as well as the actual program
code, input and output. Planning your program can take the form of a flowchart,
pseudocode, or notes to guide you in the development of the program.


Question 4 (5)

Write a program to remove unnecessary blanks from a text file. Your program
should read the text file and copy it to another text file, but whenever more than one
blank occurs consecutively, only one blank should be copied to the second file. The
second file should be identical to the first file, except that all consecutive blanks have
been replaced by a single blank.

If the input file e.g. looked like this:

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
SMARTDOCS Cambridge University
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
29
Lid sinds
3 jaar
Aantal volgers
27
Documenten
144
Laatst verkocht
1 jaar geleden
SmartDocs

Latest exam pack questions and answers and summarized notes for exam preparation. for assistance. All the best on your exams!! Thanks for visiting my store !!

3,7

7 beoordelingen

5
3
4
1
3
2
2
0
1
1

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen