100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1512 ASSIGNMENT 02 ANSWERS/SOLUTIONS 2024 $4.93
Add to cart

Class notes

COS1512 ASSIGNMENT 02 ANSWERS/SOLUTIONS 2024

 10 views  1 purchase
  • Course
  • Institution

The document above is a memo for COS1512 ASSIGNMENT 2 2024

Preview 3 out of 17  pages

  • July 11, 2024
  • 17
  • 2023/2024
  • Class notes
  • Ms portia buthelezi
  • All classes
avatar-seller
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 schoema@unisa.ac.za. 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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller JayJo. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $4.93. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

52355 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$4.93  1x  sold
  • (0)
Add to cart
Added