You're going to want to reconsider majors, I'm afraid.
"do your magic here" simply means "write the code that belongs in the function".
The function is named area, and it takes a Carpet as parameter. Sounds like it
should return the area of the carpet.
i can't run it due to this error:
:\Documents and Settings\Administrator\Desktop\proj2\carp2.cpp(13) : warning C4305: '=' : truncation from 'const double' to 'float'
C:\Documents and Settings\Administrator\Desktop\proj2\carp2.cpp(14) : warning C4305: '=' : truncation from 'const double' to 'float'
C:\Documents and Settings\Administrator\Desktop\proj2\carp2.cpp(24) : error C2601: 'displayArea' : local function definitions are illegal
Error executing cl.exe.
To everyone on the forum: If you absolutely must give out complete answers, at least put in some obscure syntax error and state that you did so. I do that from time to time.
-Albatross
To the kid: Just write a main function that creates a Carpet and defines how long and how wide it is.
-Albatross
To qdongfang: That was a direct answer to his problem. Nice, though if you used a base class pointer... nah. Never mind.
Pretty basic structure. Since you know you can cin values to the Carpet's data members, what else can you do with the data members? I'm going to hard code some values in the sample code below, but you can eaisly cin values to the Carpet
1 2 3 4 5 6 7
Carpet rug; // declares a structure named "rug" of type Carpet.
rug.legnthInFeet = 14.5; // hard coded value for the rug's lengthInFeet data member.
rug.widthInFeet = 12.2; // hard coded value for the rug's widthInFeet data member.
Now that you know you have good values in two data members, you could do just about anything to them...
1 2 3 4 5 6 7 8
float temp;
temp = rug.lengthInFeet - rug.widthInFeet; // subtract widthInFeet from lengthInFeet and assign that value to temp.
rug.lengtheInFeet = rug.widthInFeet * 50; // multiply the widthInFeet by 50 and assign that value to "rug's" lengthInFeet data member
// etc.
Now how would you determine the area if you have both the length and width stored in data members of a structure?
Remember when you pass a structure into a function, you are sending the whole structure, and the function will have access to a copy of all those data member values...
1 2
// sample function header
float area( Carpet ); // this function will receive a Carpet and return a float value....
When you figure it out it will be an AH HA moment!! :D Good Luck!
u dont have to say sorry but u did a great job, u just give me an idea.
@all
i know the answer stated above is not the real answer but an idea.
aside from this forum, i have different reference forum.
so i compile the answers from the users and study the structure of
of their statement, at last i got what i've been looking for..
thank you very much for the time that everyone spent in my post,
this forum is a MUST for a beginner like me a very NOOBISHKID.
i guess its a bout time to close this thread to prevent flaming..
@Shadow Addict
@blackcoder41
I think getArea() (Carpet &myCarpet) will be faster than getArea(Carpet myCarpet).
Use pointer or reference not a copy of the object myCarpet as parameter will be faster.
ok i know that this is gonna sound funny but what is the struct, float, and all the other fun stuff mainly used for and also could the person of just made a simple little program that goes allong the lines of something like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main ()
{
int l;
int w;
cout << "enter length: ";
cin >> l;
cout << "enter width: ";
cin >> w;
cout << l*w;
cout << " is the area."return 0;
}
because i think that would of been alot faster and easyer then having to remake one code ten times
this only is a little area finding program that i built in my free time that finds the area of rectangle or a square
so what are the differences between my code and what the other code is required to be because personally i think my code is in nicer shape but thats only cause what i made i can fully understand whatever my code has and the other code have in common like cin and cout thats about the only things that are similar please help solve this minor issue.
because i think that would of been alot faster and easyer then having to remake one code ten times
Yes, but that's not what OP was asked to do.
Create a structure named Carpet that has two public data members: lengthInFeet and widthInFeet. Write a main() function that instantiates a Carpet object and assigns values to its fileds. Pass the object to a function named Area() that calculates the carpet area in square feet and displays the results. Save the file as Carpet.cpp