Results 1 to 5 of 5

Thread: (C) + + Table Structure

  1. #1
    willi is offline Senior Member
    Join Date
    Jan 2009
    Posts
    148
    Rep Power
    4

    Default (C) + + Table Structure

    Hello, I started in C + + and I want to make a table structure
    I do this:
    * body = new body tableau_de_corp [N]

    With body is poised of structures coordinates (x, y) describes the acceleration, velocity as well as position of a tip.

    Code:
    1.	# include <iostream>
    2.	
    3.	
    4.	# include <cmath>
    5.	# define G 6.67E-11
    6.	# define N 2
    7.	using namespace std;
    8.	
    9.	
    10.	
    11.	
    12.	struct Coordonnees
    13.	(
    14.	float x;
    15.	float y;
    16.	);
    17.	
    18.	struct body (
    19.	float mass;
    20.	Position coordinates;
    21.	Coordinates speed;
    22.	Acceleration coordinates;
    23.	
    24.	);
    25.	
    26.	calcul_acceleration void (* tableau_de_corps body = new body [2])
    27.	(
    28.	* Coordinates = new tableau_de_acc Coordonnees [N];
    29.	for (int i = 0; i <(N-1) i + +)
    30.	(
    31.	tableau_de_acc [i]. x = (tableau_de_corps [i +1]. mass) * ((tableau_de_corps [i +1]. (position)). x - (tableau_de_corps [i]. (position)). x) / abs ( pow (norm (tableau_de_corps [i]. (position). tableau_de_corps-x [i +1]. (position). x, 3));
    32.	tableau_de_acc [i]. y = (tableau_de_corps [i +1]. mass) * ((tableau_de_corps [i +1]. (position)). y - (tableau_de_corps [i]. (position)). y) / abs ( pow (norm (tableau_de_corps [i]. (position). tableau_de_corps-y [i +1]. (position). y, 3));
    33.	court <<tableau_de_acc [i] <<endl;
    34.	
    35.	)
    36.	tableau_de_acc [i]. y *= G
    37.	tableau_de_acc [i]. x *= G
    38.	)
    39.	
    40.	
    41.	float norm (coordinated vector)
    42.	(
    43.	float n = sqrt (pow (vecteur.x, 2) + pow (vecteur.y, 2));
    44.	return n;
    45.	)
    46.	
    47.	
    48.	
    49.	int main ()
    50.	(
    51.	tableau_de_corps * body = new body [N] / / No creation of body
    52.	
    53.	calcul_acceleration (tableau_de_corps []);
    54.	return 0;55.	)
    My trouble lies in the void calcul_acceleration. If for instance in the first box and there is a body, I want to alter some of the details of the acceleration, should I write:

    Code:
    1.	(tableau_de_corps [i +1]. (position)). x
    or

    Code:
    1.	(tableau_de_corps [i +1] -> (position)). x
    Or something else?

    Thank you in advance

  2. #2
    gorden is offline Senior Member
    Join Date
    Jan 2009
    Posts
    148
    Rep Power
    4

    Default

    I read a course on std: vector. So I change my old vector table. That said, I still have the problem with the syntax:

    (tableau_de_corps [i +1]. (position)). x

    Thank you.

  3. #3
    chreshel is offline Senior Member
    Join Date
    Jan 2009
    Posts
    139
    Rep Power
    4

    Default

    eneleve your brackets they are useless.

  4. #4
    aldrin is offline Senior Member
    Join Date
    Jan 2009
    Posts
    153
    Rep Power
    4

    Default

    Okay great!

    Almost everything works, I have no error in the formula, cons by something blocking the main ():

    Code:
    1.	# include <vector>
    2.	# include <iostream>
    3.	# include <cmath>
    4.	# define G 6.67E-11
    5.	# define N 2
    6.	using namespace std;
    7.	
    8.	
    9.	struct Coordonnees
    10.	(
    11.	float x;
    12.	float y;
    13.	);
    14.	
    15.	struct body (
    16.	float mass;
    17.	Position coordinates;
    18.	Coordinates speed;
    19.	Acceleration coordinates;
    20.	
    21.	);
    22.	
    23.	Coordinates operator - (coordinates a, b Coordonnees)
    24.	(
    25.	Coordinates res;
    26.	res.x = ax-bx;
    27.	res.y = ay-by;
    28.	return res;
    29.	)
    30.	
    31.	float norm (vector Coordonnees)
    32.	(
    33.	float n = sqrt (pow (vecteur.x, 2) + pow (vecteur.y, 2));
    34.	return n;
    35.	)
    36.	
    37.	
    38.	calcul_acceleraton void (vector <body> tableau_de_corps)
    39.	(
    40.	* Coordinates = new tableau_de_acc Coordonnees [N];
    41.	int i = 0;
    42.	for (i, i <(N-1) i + +)
    43.	(
    44.	tableau_de_acc [i]. x = (tableau_de_corps [i +1]. mass) * (tableau_de_corps [i +1]. position.x);
    45.	tableau_de_acc [i]. x = (tableau_de_corps [i +1]. mass) * (tableau_de_corps [i +1]. position.x - tableau_de_corps [i]. position.x) / abs (pow (norm (tableau_de_corps [i] . tableau_de_corps-position [i +1]. position), 3));
    46.	tableau_de_acc [i]. y = (tableau_de_corps [i +1]. mass) * (tableau_de_corps [i +1]. position.y - tableau_de_corps [i]. position.y) / abs (pow (norm (tableau_de_corps [i] . tableau_de_corps-position [i +1]. position), 3));
    47.	court <<tableau_de_acc [i]. x <<endl;
    48.	
    49.	)
    50.	tableau_de_acc [i]. y *= G;
    51.	tableau_de_acc [i]. x *= G;
    52.	)
    53.	
    54.	
    55.	
    56.	int main ()
    57.	(
    58.	vector <corps*> liste_corps / / No creation of body
    59.	calcul_acceleraton (vector liste_corps) Missing template arguments before 'liste_corps'
    60.	return 0;61.	)
    Missing template arguments before 'liste_corps' on the line calling the function calcul_acceleration
    Voila, thank you, I think (hope) that it will be the last question.

    PS: I still have a second concern, I have tried to

    Code:
    1.	liste_corps [1]. position.x = 1;
    I put the following error:

    Code:
    1.	error: request for member 'position' in 'liste_corps. std:: vector <_Tp, _Alloc>:: operator [] [with _Tp = body *, _Alloc = std:: allocator <corps*>] (1UL) 'Which is of non-class type' body * '

  5. #5
    joshin is offline Senior Member
    Join Date
    Jan 2009
    Posts
    145
    Rep Power
    4

    Default

    Yes. I repeat:

    you make a vector <corps*> so you create an array of pointers, but nothing sets. You have a vector Besin <body> (and this time leave it. Position).

Similar Threads

  1. Difference among delete table & prune table
    By MorganCooper in forum Programming
    Replies: 1
    Last Post: 02-10-2010, 04:22 PM
  2. MySQL Display Table Structure Software 7.0
    By Alicia Cole in forum Download Tools and Softwares
    Replies: 0
    Last Post: 08-21-2009, 10:57 AM
  3. Designing a table structure from tabbed text
    By Jairus Clovelly in forum Programming
    Replies: 0
    Last Post: 07-06-2009, 06:38 AM
  4. Sound structure
    By terank in forum Web. 2.0
    Replies: 0
    Last Post: 06-25-2008, 03:16 PM
  5. Sound structure
    By wenssal in forum Web. 2.0
    Replies: 0
    Last Post: 06-21-2008, 06:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48