I've been reading quite alot but i still cannot understand the use of structures.
I'm given the following exam:
You have to find the frontage and the perimeter of triangle ,that is composed in coordinate plane 0xy,by inputting edge ( the edge is C for example of A,B,C).
I have to be using structure for POINT and TRIANGLE.This means that the edge of the triangle is not regular variable but member-variable of structure.I'm obligated to define structure for point with member-variable xc and yc - coordinates of point.
I'm still struggling to understand what am i obligated to actually do.The part with the structures is really confusing me ... anyone can clarify it to me or show it with an example so i can try something and post my code here for checkup ..
By now i know only how to input the libraries and calculate the frontage and the perimeter ( the noobie stuff).
struct Point
{
float x;
float y;
};
struct Triangle
{
Point A;
Point B;
Point C;
};
// in code:
Point SomePoint = {10.0f, 10.0f};
// this is the same as writing:
// Point SomePoint;
// SomePoint.x = 10.0f;
// SomePoint.y = 10.0f;
Point SomeOtherPoint = {10.0f, 20.0f};
Point SomeThirdPoint = {20.0f, 10.0f};
Triangle SomeTriangle = {SomePoint, SomeOtherPoint, SomeThirdPoint};
printf("SomeTriangle.A == (%f/%f)\n", SomeTriangle.A.x, SomeTriangle.A.y);
a structure is like a new type which can hold multiple variables.
EDIT:
however - if you want to use C++ (and not C), you may prefer classes (which for example allows you to declare functions bound to the structure, so you may create Point.Length() function etc.).
EDIT:
however - if you want to use C++ (and not C), you may prefer classes (which for example allows you to declare functions bound to the structure, so you may create Point.Length() function etc.).
The only difference between classes and structs in C++ is, that in structs everything is public by default and private in classes. Otherwise they behave the same.
See:
The only difference between classes and structs in C++ is, that in structs everything is public by default and private in classes. Otherwise they behave the same.
See:
however, this is C++ and in my opinion bad style to use structs with functions since C++ offers classes for this.
I'm obligated to use structure in C++ ,using classes would make it more complex as we didn't pass the material.
So when i create the structures i'm not sure how to define side A/B/C using the structures .. well here is what my brain created ( note i'm really a beginner in C) :
Code:
#include <isotream.h>
#include <math.h>
void main()
{
struct Point
float x;
float y;
};
struct Triangle
{
point A;
point B;
point C;
};
while ((x>0) & (y>0));
cout <<"\n Please input value for x";
cin >> x;
cout <<"\n Please input value for y";
cin >>y;
Side A = x;
Side B = y;
Side C = sqrt((x*x)+(y*y));
cout << "\n The hypotenuse is:";
P = point A + point B + point C;
S = sqrt(P*(P - side A)*(P - side B)*(P - side C));
cout<<"\n S=";
cout<<"\n P=";
// end main
All in all , the program should build triangle by given edge ( C) then calculate it's S,P. Apart from that it has to record the output values in text file and read the file before every new executing(which i'm still digging on the net how-to).Still no clue how to combine structures so that on the display i have to enter edge of the triangle to get it build ...
Second day of learning C++ - burning brain.
however, this is C++ and in my opinion bad style to use structs with functions since C++ offers classes for this.
That's not true, because there are still situations in which structs fit better and sometimes you want to have structs with more functionality (i.e. constructor or operators).
however, this is C++ and in my opinion bad style to use structs with functions since C++ offers classes for this.
Well, too bad an opinion is not an actual argument.
Quote:
I'm obligated to use structure in C++ ,using classes would make it more complex as we didn't pass the material.
As I've said, there is no difference (beside everything is public by default in structs) between them.
Also, you misinterpreted Dr. Coxxys Code (not entirely your fault though). You have to put structs outside of your main (or for that matter any) function.
Oh, and you might want to put your code inside [ code ] tags instead of [ quote ]. Then your formatting doesn't get ****** up.
So the structure must be above or after main .... and how to use the variables from the structure ... i mean how to us them in some function outside the structure ...
Because i have to calculate the S and P for N triangles ( n=unknown number) so i guess imma use cycle program with a pointer i ( so i++ on every cycle).
However i still do not understand how to build the **** triangles using these structures , otherwise finding S and P is just maths ... this **** is driving me crazy ....
So the structure must be above or after main .... and how to use the variables from the structure ... i mean how to us them in some function outside the structure ...
Because i have to calculate the S and P for N triangles ( n=unknown number) so i guess imma use cycle program with a pointer i ( so i++ on every cycle).
However i still do not understand how to build the **** triangles using these structures , otherwise finding S and P is just maths ... this **** is driving me crazy ....
By declaring a struct you're making a new type like int or double. So you can make a variable of that type like with any other type. You access its underlying variables with the "." operator.
Play a bit around with it and familiarize yourself with it and then try to use it in your problem.
#include <iostream>
#include <math.h>
using namespace std;
struct Coordinate
{
float x;
float y;
};
struct Triangle
{
float SideA;
float SideB;
float SideC;
};
int main()
{
int i=0;
int N;
cout<<"\nInput x";
cin>>Coordinate.x;
cout<<"\nInput y";
cin>>Coordinate.y;
Triangle.SideA = Coordinate.x;
Triangle.SideB = Coordinate.y;
Triangle.SideC = sqrt((Coordinate.x*Coordinate.x)+(Coordinate.y*Coordinate.y));
cout<<"\nTriangle.SideC=";
P= Triangle.SideA+Triangle.SideB+Triangle.SideC;
cout<<"\nP=";
S = sqrt(P-(P-A)*(P-B)*(P-C));
cout<<"\nS=";
for(int i=0; i<N; i++)
}
// end main
And i'm getting full of errors by the compiler ... says most of my variables are undeclared -_- .@nightblizard thanks btw i understood how to combine and use the structures ... but what is wrong in my code ... why the compiler is returning with errors regarding undeclared A B C x y and so on ... also it says something is wrong with my library math ...
Yeah, you have to declare a variable of type Triangle and Coordinate before you can use them. Look at line 11 in my example.
I declare a variable "foo" which type is "Foo". After that I have access to foo.bar and foo.meow (you access them via the variables name, not by the structs name).
Thanks alot guys i finally got it ... but it seems the task is going to be more complex ... i'm still getting it clear with the teacher(***,he is real pain in the a$$ -_- )
Little issue 10/13/2011 - Dekaron Private Server - 4 Replies Ladies and Gentlemen, i have a little and noob Problem.
I Downloaded the Aloken server files with the Dekaronserver.exe, Dekaron.exe and the character.bak (ItsNobody database).
I placed the dekaronserver.exe in the appropriate folder inside the virtual machine.
I placed the dekaron.exe in the appropriate folder inside the A9 client.
What i should do with the character.bak? i know it is something to do into databese, but i really dont know how i should start.
Can someone tell me...
Issue with DB-Bot 07/14/2010 - SRO Private Server - 3 Replies Hello,
when I add a new skill in the bot or when I update a skill it always says: the selected item cannot be used together or the skill is already in use. But the old skill is gone in the game and in the bot but still it says that.. Really frustrating
I play on ZSZC sro...
AC/Bot issue 07/15/2008 - MapleStory - 0 Replies i have tryed many ac/bot that woked for many ppl but it doesn't for me. I download the ac/bot annd folo the intruction completly. i start up the ac/bot and then run my private server. in the server i click the hotkey but nothing happenes. it says the ac is enable but nothing happens. help me plz i'm really getting frustrated.
SV Issue 11/18/2007 - Conquer Online 2 - 7 Replies Basically after i press start sv just does nothing apart from hop around a bit now and again. On co there is a msg 'can't jump that far' dont know if that has anything to do with it. sv was working fine before, then it did this and when i tried the next day it worked for some reason, now it wont work again. fyi im using sv 1.17 with ce on patch 4356, help very much appreciated as i have tried everything including fresh co install.