100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1512 Semester 2 School of Computing This tutorial letter contains the solution to Assignment 2 $7.49   Add to cart

Exam (elaborations)

COS1512 Semester 2 School of Computing This tutorial letter contains the solution to Assignment 2

 3 views  0 purchase
  • Course
  • Institution

COS1512 Semester 2 School of Computing This tutorial letter contains the solution to Assignment 2

Preview 4 out of 32  pages

  • March 8, 2022
  • 32
  • 2021/2022
  • Exam (elaborations)
  • Questions & answers
avatar-seller
COS1512/202/2/2016




Tutorial letter 202/2/2016


Introduction to Programming II
COS1512

Semester 2


School of Computing

This tutorial letter contains the
solution to Assignment 2



IMPORTANT INFORMATION:
Please activate your myUnisa and myLife email addresses and ensure you have
regular access to the myUnisa module site COS1512-2015-S2 as well as your e-
tutor group site.

Due to regulatory requirements imposed by the Department of National Education
the following apply:

To be considered for examination admission in COS1512, a student must meet
the following requirement:
Submit assignment 1 or assignment 2 BEFORE 9 September 2016.

Note: This is a blended online module, and therefore your module is available on myUnisa.
However, in order to support you in your learning process, you will also receive some study
materials in printed format. Please visit the COS1512 course website on myUnisa at least
twice a week.

, 2



Content
1. Introduction .................................................................................................................................... 2
2. Tutorial matter distributed to date ................................................................................................... 2
3. Allocation of marks ......................................................................................................................... 3
4. Solution to Assignment .................................................................................................................. 2


1. Introduction
The purpose of this tutorial letter is to supply the solution for Assignment 2, and to indicate how you should
interpret the results you obtained for this assignment. This assignment covers the work discussed in
Chapters 10, 11 and 12 of the Study Guide (Tutorial Letter 102), as well as the relevant sections in
Chapters 10, 11 and 12, and Appendices 7 and 8 of Savitch. Note that you should have included the input
and output of all programs you were required to write.

The assessment and feedback given on your assignment, serve as an indication of your mastering of the
study material.
If you received a good mark, you can be confident that you are on the right track. If you did not receive a
good mark, it is an indication that you need to revise your study method for COS1512.


2. Tutorial matter distributed to date
DISK 2016 Prescribed software
COS1512/101/3/2016 First tutorial letter: General information, study programme, exam admission
and assignments
COS1512/102/2/2016 Study Guide
COS1512/103/2/2016 How to create an assignment as a PDF file
COS1512/201/2/2016 Solution to Assignment 1
COS1512/202/2/2016 This letter: Solution to Assignment 2


If you have not received all of the above-mentioned tutorial matter, please download it from myUnisa at
https://my.unisa.ac.za.

, 3 COS1512/202/2/2015



3. 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 2 is 80. This is converted to a
percentage. If you for instance obtained 40 marks for Assignment 2, you received 50% for Assignment
2. This percentage in turn contributes a weight of 80% 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

Questions 3, 4 and 6 have not been marked. However, 5 marks are awarded if you attempted questions 3,
4 and 6 (note that this is not the way in which questions will be marked in the examination!). We include
complete solutions for all questions.

The marks you received for question 1 were 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 2 were determined on the following basis:
Question not done 0/30
Each correct response to questions (a,c,d,i,j,k,l,m,n and q) = 2 marks 20/30
Each correct response to questions (b,e,f,g,o,p and r) = 1 mark 7/30
Question (h) = 3 marks 3/30


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


In other words, you can obtain a maximum of 5 marks for questions 1, 3, 4 and 6; a maximum of 30 marks
for question 2; and a maximum of 15 marks for questions 5 and 7.

Note that not all mistakes are corrected – but we will provide informative comments.

If you did not include the program output for questions 1, it means there are “a few problems with your
answer” and the maximum you can get is then 4/5. If you did not include the program output for questions 5
and 7, it means there are “a few problems with your answer” and the maximum you can get is then 12/15.

We did not award any marks to assignments submitted more than four weeks after the due date. However,
we still provided informative comments.

, 4



4. Solution to Assignment
Question 1 [max of 5 marks]

Discussion:
For this question, you had to convert the struct Bankdetails into a class. There is essentially only a
slight difference between a struct and a class. A class is the same as a struct (i.e. a struct may
also contain both member variables and member functions just like a class, even though the examples in
Savitch do not show that) except that, by default, all members are inaccessible to the general user of the
class. This means that all members of a struct are by default public, and all members of a class are by
default private. Therefore, we have to specify that the member functions are public. (As an exercise,
omit the public keyword from the class and recompile it.) While there are situations where a struct is
more suitable, as a rule, you should use classes rather than structs. In general, it is preferable to use
classes, as classes offer better protection.

An object encapsulates or combines data and operations on that data into a single unit. In C++, the
mechanism that allows you to combine data and the operations on that data in a single unit is called a
class.

A class can be seen as a user-defined data type. We use a class to declare or instantiate an object.
When an object of a specific class is instantiated, the constructor for the class is called by default. The
purpose of the constructor is to initialise the member variables of the object automatically. This means that
a constructor should not include instructions to obtain values for the member variables (cin statements). It
also means that the member variables should not be re-declared inside the constructor, since these
variables will then be local to the function, and will prevent the constructor function from accessing the
member variables to initialise them. Study the constructor for class Bankdetails as shown below to see
how these concepts are implemented:
//implementation
Bankdetails:: Bankdetails () //constructor
{
Name = " ";
Type = " ";
Accnr = 0;
Branch = 0;
}
As Name, Type, Accnr, and Branch are private member variables (see page 549 of Savitch 6th edition/
page 581 of Savitch 7th edition/ page 579 of Savitch 8th edition/ page 595 of Savitch 9th edition) of class
Bankdetails, they cannot be accessed directly in the main() function. As a result, public member
functions getName(), getType(), getAccnr() and getBranch() are used to access these member
variables in order to determine their values. These functions are known as accessor functions, while
setName(), setAccnr(), setType() and setBranch() are mutator functions. (Study pages 553 –
554 of Savitch, 6th edition/ pages 585 -586 of Savitch 7th edition/ pages 581 -582 of Savitch 8th edition/
pages 597-598 of Savitch 9th edition).

Note the prototypes for member functions:
double getAccnr() const;
string getType() const;
double getBranch() const;
string getName() const;
These member function are accessors - hence the const keyword at the end of the function definition. Note
that a member function that does not have the const keyword at the end of it may possibly mutate (change
or modify) the state of the object.

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 NURSMontero. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

78834 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
$7.49
  • (0)
  Add to cart