100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4,6 TrustPilot
logo-home
Class notes

COS1512 ASSIGNMENT 02 ANSWERS/SOLUTIONS 2024

Rating
-
Sold
1
Pages
17
Uploaded on
11-07-2024
Written in
2023/2024

The document above is a memo for COS1512 ASSIGNMENT 2 2024











Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
July 11, 2024
Number of pages
17
Written in
2023/2024
Type
Class notes
Professor(s)
Ms portia buthelezi
Contains
All classes

Subjects

Content preview

COS1512/201/2/2018




Tutorial letter 201/2/2018
Introduction to Programming II


COS1512
School of Computing
This tutorial letter contains the
solutions to Assignment 1

, COS1512/201/2/2018

INTRODUCTION

By the time you receive this tutorial letter you should have already completed assignment 1 and we
hope that you are well on your way with your studies. This tutorial letter contains the solutions to
Assignment 1. You are welcome to e-mail me with any queries at . Also take
note of the following telephone number and the days on which the lecturer are available in case you
have to call.

Mondays Dr MA Schoeman 011 670 9178
Tuesdays Dr MA Schoeman 011 670 9178


Allocation of marks
When we mark assignments, we comment on your answers. Many students make the same mistakes
and consequently we discuss general problems in the tutorial letters. It is, therefore, important to work
through the tutorial letters and to make sure you understand our solutions and where you went wrong.
The maximum number of marks you could obtain for Assignment 1 is 40. This is converted to a
percentage. If you for instance obtained 28 marks for Assignment 1, you received 28/40 * 100 = 70%
for Assignment 1. This percentage in turn contributes a weight of 20% to the year mark, as can be
seen in the summary of the weights allocated to the assignments for COS1512 below.

Assignment
Weight
number
1 20
2 80
3 0

We give the mark allocation for the questions below. For questions 1 – 4 you will not get any marks if
you did not include the program code. Or if you only included part of the code, you will get a maximum
of 2 marks if the included code is correct. Please note that this is NOT the way exam answers will
be marked. In the exam you will receive marks for specific statements as indicated by the exam
question. The purpose of the assignments is to provide you with an opportunity to practice the
concepts you are studying. Your marks for the assignment is an indication of whether or not you could
implement those concepts. If you did not include the output for your program, you will not get full
marks for the question. We discuss a possible solution for each question below. Please read through
the solution and discussions thoroughly.

The marks you received for question 1 was determined on the following basis:
Question not done 0/10
Question attempted, but the program does not work at all 4/10
A good attempt, but there are a few problems with your answer 8/10
The program works correctly and produces the correct output 10/10

The marks you received for question 2 was determined on the following basis:
Question not done 0/5
Question attempted, but the program does not work at all 2/5
A good attempt, but there are a few problems with your answer 4/5
The program works correctly and produces the correct output 5/5

The marks you received for question 3 was determined on the following basis:
Question not done 0/15
Question attempted, but the program does not work at all 5/15
A good attempt, but there are a few problems with your answer 11/15
The program works correctly and produces the correct output 15/15


2

, COS1512/201/2/2018


The marks you received for question 4 was determined on the following basis:
This question was not marked. If you attempted the question, you will get 5 marks. If not, you will get 0
marks. Please go through the solution that we give for question 4 to make sure that you understand
how to work with text files.

The marks you received for question 5 was determined on the following basis:
This question was not marked. If you attempted all the questions, you will get 5 marks. If you have not
attempted both questions 5(m) and (n), you will get 2 marks. If you have not attempted one of
questions 5(m) or 5(n), you will get 3 marks. If you have not attempted the question at all, you will get
0 marks. Please go through the solution that we give for question 5 to make sure that you understand
how to work with pointers.


Solution to Assignment

Question 1 10 marks

For this question you had to write a program to use two overloaded functions, each named
calcPostage(), to determine the postage for a parcel to London via GlobalMail or DHL. If GlobalMail
is chosen, the cost is R108 per kg if the parcel goes to zone 1 to 3 in London, and R130 per kg if the
parcel goes to zone 4 to 6. If DHL is chosen, the actual weight is compared to the volumetric weight,
and whichever is the higher weight, is used in the calculation. The volumetric weight is calculated by
the formula (length * width * height) / 5000, where length, width and height is the size of the box in cm.
The cost per kg for DHL is R70.
Function overloading is the practice of declaring the same function with different signatures. This
means that the same function name will be used with a different number of parameters and/or
parameters of different types. But overloading of functions with different return types is not allowed. In
this question you had to write an overloaded function named calcPostage with either two
parameters (one of type double and one of type int), or four parameters of type double. Although it
was not specified in the question, our program only displays two digits after the decimal point.


Program listing
//Ass 1 question 1
#include <iostream>
using namespace std;
const double zone1to3 = 108.00;
const double zone4to6 = 130.00;
const double DHL = 70.00;
const double factor = 5000;

//overloaded function GlobalMail
//Pre: weight in kg and the zone
//Post: returned cost for sending the parcel
double calcPostage (double weight, int zone);

//overloaded function for DHL
//Pre: actual weight and length, width and height of parcel
//Post: returned cost for sending the parcel
double calcPostage (double weight, double length, double width, double
height);


int main()


3

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
JayJo University of South Africa (Unisa)
View profile
Follow You need to be logged in order to follow users or courses
Sold
51
Member since
4 year
Number of followers
46
Documents
24
Last sold
2 months ago

4,0

4 reviews

5
3
4
0
3
0
2
0
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions