0

I am trying to solve the question below, but I do not understand it very well. Do I need to use overloading, although it doesn't say that? How could I get started?

Create a class that imitates part of functionality of the basic data typ int. Call the class Int. The only data in this class is int variable. Include member functions to initilize an Int to 0, to initilize it to an int value, to display it and to add two int values.

Write a program that excersices this class by creating two initilized and one uninitilized Int values, adding these two initilized values and placing the response in the uninitilized value and then displaying this result.

Bart
  • 19,692
  • 7
  • 68
  • 77
Aan
  • 12,247
  • 36
  • 89
  • 150
  • 4
    So what have you tried to do so far? – Tudor Dec 11 '11 at 14:29
  • 9
    So you are following a programming class, course, or tutorial. You *should* be able to find the answers to that question in the material of that class, course, or tutorial. Applying that material towards solving the question is called "transfer of learning", and it is *essential* in actually achieving the *goal* of the class, course, or tutorial. By asking your question on the internet instead, you are aiming not at learning how to program, but at asking questions on the internet. By giving the answer, we would actually do you a disfavor. – DevSolar Dec 11 '11 at 14:37
  • @DevSolar: This should be printed, framed and displayed in every classroom. – Tudor Dec 11 '11 at 14:46
  • Given that [this is your previously asked question](http://stackoverflow.com/questions/8464172/overload-operators-to-work-with-class-objects), your current one should be rather obvious. – Bart Dec 11 '11 at 14:56
  • @DevSolar: Not that I disagree, but asking questions on the Internet is an underrated but very rare and useful skill. – Staven Dec 11 '11 at 14:59
  • See what [they](http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html) did. It's java but it may be a good starting point in order to give you an idea. – INS Dec 11 '11 at 14:59
  • 1
    @DevSolar: There exist many horrible classes--where the teachers are either lazy or just plain incompetent--whose lessons are more copy-and-paste than any internet homework answer. So imagine how bad learning in a non-English country might be! Fault does not always lie with the student: if the actual phrase *"member functions to initilize [sic] an int to 0"* is used in the assignment then the OP is already fighting an uphill battle, and there's nothing wrong (and everything right) with the Internet helping with terminology distinguishing constructors from member functions, etc. – HostileFork says dont trust SE Dec 11 '11 at 15:00
  • @Staven: It's not asking questions that is the underrated, usefull skill, it's *finding answers*. Google trumps SO.com. Even entering the title of the question in Google would have helped the OP. – DevSolar Dec 11 '11 at 15:34
  • @HostileFork: Are you suggesting that people who live in a non-English-speaking country are incapable of the fundamental human skill of _learning_? Bit racist? – Lightness Races in Orbit Dec 11 '11 at 20:39
  • @TomalakGeret'kal Not at all. I'm saying if teachers are copying and pasting fragmented lessons from questionable sources in a language you don't speak natively, the confusion snowballs even more. Beyond that, languages do not "belong" to any race...if I said "I hate people who speak French" then how would that be racist? – HostileFork says dont trust SE Dec 12 '11 at 02:49
  • @HostileFork: And how do you know that they're copying it from a language you don't speak natively? Maybe they're copying it from sources in your language. Just because they're not English, doesn't change that. – Lightness Races in Orbit Dec 12 '11 at 07:54
  • @TomalakGeret'kal This is very fascinating, let's talk about it for ten more comments. – HostileFork says dont trust SE Dec 12 '11 at 14:52
  • @HostileFork: Let's not. – Lightness Races in Orbit Dec 12 '11 at 15:54

2 Answers2

4

Sounds like you have to create a class that holds an int and implement some overloaders (==, >, <, +, -, ++, --, etc) which manipulate this int.

Edit as DevSolar mentioned in the comments to the question, it's not right to actually give answers in code because there's a homework tag. I explained the question, good luck!

Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105
0

Start by creating a class called 'Int', next add the 'int varible' as per the question. Next add the constructor and member functions that the question asks for.

Finally create the program to use the class you have created. If you have been learning about operator overloading then you could use it if not then it is up to you , you could just use a function to add 2 Int's.

Jase
  • 31
  • 3