implementation methods

General discussion about C/C++

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

implementation methods

Postby georgio » Tue Sep 30, 2003 7:48 am

Hi, i am revising for an exam, and i am having trouble asnwering a question on a past paper, i was wondering if anyone could please help me with this question.

the class below represents a cubic box:

Cube

side

get side()
getVolume()

the attribute shown representing the size of each of its sides. it cotains no set.. method for the attribute side; instead write the implementation for a constructor method which will initiate this value when an object of the class is created.

part b) write the implementation of the method getVolume()..

thanks very much
georgio
 

Postby Justin » Tue Sep 30, 2003 10:17 am

speak english, not engrish

This all requires no brain, it's that easy.

void cube::cube(int s=0) {
size = s;
}

Hard huh? You can do the volumn one yourself. It's easy too. All it is is a matter of multiplying size * size * size.
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA

Postby RecursiveS » Tue Sep 30, 2003 11:48 am

Justin wrote:speak english, not engrish


Please remember that this site has members from all over the world - for some, english is not their first language.

I have seen far worse spelling & grammar from people for whom english is their first language.

Please be tolerant....

/pompous speech......

:)
User avatar
RecursiveS
Site Admin
 
Posts: 1236
Joined: Thu Sep 18, 2003 8:33 am
Location: Dorset, UK

Postby gooch » Tue Sep 30, 2003 1:07 pm

Justin wrote:This all requires no brain, it's that easy.

void cube::cube(int s=0) {
size = s;
}

Hard huh?


must be, since even you screwed it up ;) remove the void keyword. heh.
gooch
 
Posts: 74
Joined: Thu Sep 25, 2003 4:12 am

Postby Jimbo » Tue Sep 30, 2003 4:42 pm

gooch wrote:must be, since even you screwed it up ;) remove the void keyword. heh.


:lol: thats pretty funny...
User avatar
Jimbo
 
Posts: 601
Joined: Thu Sep 25, 2003 6:48 pm
Location: Seattle

Postby jgbauman » Wed Oct 01, 2003 2:13 am

cube::cube(int s=0):size(s) {}

is even more C++ style.
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am

nnnn....

Postby AMIT » Wed Oct 01, 2003 4:54 am

Justin wrote:speak english, not engrish

This all requires no brain, it's that easy.

void cube::cube(int s=0) {
size = s;
}

Hard huh? You can do the volumn one yourself. It's easy too. All it is is a matter of multiplying size * size * size.



:lol: speaking english not engrrish amit telling u
AMIT
 

Postby Justin » Wed Oct 01, 2003 12:04 pm

wow. i just got toasted. :( I'll should code more in C++ and less in php, maybe then i'll remember how to code a proper constructor.
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA

Postby MXP » Wed Oct 01, 2003 5:17 pm

Justin wrote:wow. i just got toasted. :( I'll should code more in C++ and less in php, maybe then i'll remember how to code a proper constructor.


Your constructor was correct though.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Justin » Thu Oct 02, 2003 3:39 pm

thank you :P
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA

Re

Postby Dudi Hatotah » Fri Oct 03, 2003 5:04 pm

Here is the full solution, put together:
(I think "side" was the private varaible of the cube)

Code: Select all
cube::cube(int side = 0)
{
    cube::side = side;
}

int cube::getVolume()
{
    return side * side * side;
}
User avatar
Dudi Hatotah
 
Posts: 222
Joined: Fri Oct 03, 2003 4:17 pm
Location: Micronesia, the island of Yap


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests