hi i got my second assigment here for oop in c++.
but i don't understand clearly.
can anyone explain it to me?

ASSIGNMENT 2

INTRODUCTION TO CLASS [15 marks]

Objective: 1.Learn how to write class which uses dynamic memory allocation

2. Learn how to invoke member function/send message to object

There are several ways to represent whole numbers in digital computer which are equivalent to each other. Namely,

a. Signed

b. Unsigned

c. Two complement.

Numbers are represented as binary in computer system. In this assignment you will write program about how computer treat numbers that you see as decimal integers. Particularly, we are considering unsigned representation/format.

You have to create a class named UINT that represents (unsigned) binary representation of integer. For example, the (unsigned) binary representation of 35 is 00100011 (8-bit word) or 00000000 00100011 (16-bit word).

It has int pointer type data member to store the binary digits that represent an integer number and int data member to store the length of the array of int pointer.

A constructor with int argument as initial value to the UINT object. For example, you can declare

UINT t(456);

A member function int toint() that converts the binary into int.

A member function UINT add(UINT) that adds to UINT objects(note: be careful of overflow error).

A member function void print1() that prints the binary representation of an integer number (the content of the pointer). It prints 00100011 instead of 35.

A member function void print2() that prints the decimal value of the variable. It prints 35 instead of 00100011.

A destructor that delete the pointer when a UINT object exits its scope.

UINT

-len : int

-*bin :int

+<<constructor>> UINT(:int,int=16 )

+toint() : int

+add(:UINT) :UINT

+print1()

+print2()

+~UINT

*int type variables can be replaced with short.

Fig. 1. UML Diagram of class UINT

Write main function to test the supposed capability of your program and attached the screenshot of the results on your report. For, example if you have mechanism that prevent overflow error, demonstrate it in your main function.

Recommended Answers

All 4 Replies

It's kind of hard to explain the entire assignment to you. Tell us which parts you don't get. For example do you know how to use classes? If yes: start by making the 'skeleton' of the program. (constructors/destructor/prototypes etc)
Do you know the difference between signed and unsigned?
Do you know how to convert decimal to binary?

etc etc..

It's kind of hard to explain the entire assignment to you. Tell us which parts you don't get. For example do you know how to use classes? If yes: start by making the 'skeleton' of the program. (constructors/destructor/prototypes etc)
Do you know the difference between signed and unsigned?
Do you know how to convert decimal to binary?

ok i know classes because we have learned that part.
constru.desctructor.protypes sound easy to me.
for decimal to binary not yet..
what's the formula again?

for decimal to binary not yet..
what's the formula again?

The "formula" (more like a procedure) is described in niek's link. I assume you have read it and have a specific question? Read niek's link and others, try it out, and once you have tried it several times with no luck, post a SPECIFIC question on ONE forum please, which will show, one, that you are willing to put your own time into this, and two, that you value other people's time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.