Arrays

This is a discussion on Arrays within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I'm at uni and I have some coursework involving a virtual line in C/C++. The user should be ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    1

    Arrays

    Hi guys, I'm at uni and I have some coursework involving a virtual line in C/C++.

    The user should be able to input start and end coords (3D) of this line eg X1,Y1,Z1 and X2,Y2,Z2, and execute various transformations on the line as a whole around arbitrary points eg. rotation, translation etc.

    Things is, I am stupid, and I don't even know how to set up a single 2D array to cope with this and then allow a user to modify the points in the array. I have a functioning-ish menu (see code below) but I haven't a clue about the important bits.

    Could anyone please help me on how to get the array to show its six coordinates and then allow the user to modify them at least?

    Thanks, Simon Phillips <spuk>

    NB- can be written in C or C++

    Code:
    #include <stdio.h>
    #include <stdlib.h>   //required for user to exit program
    #include <math.h>     //needed to apply maths such as sin, cos etc.
    int main()
    {
       double p1[3]={0,0,0};
       double p2[3]={0,0,0};  
       
       int option;  
       
       for (;;)
       {
          printf("\nMAIN MENU\n");
          printf("--------------------\n");
          printf("1| Set Start Point\n");                 //1. Sets start point of line
          printf("2| Set End Point\n");                   //2. Sets end point of line
          printf("3| Apply Translations\n");              //3. Translates the line by user-selected amount
          printf("4| Apply Rotation\n");                  //4. Rotates the line by user-selected amount
          printf("5| Apply Scaling\n");                   //5. Scales the line by user-selected amount
          printf("6| Evaluate Line\n");                   //6. User selects a point along line between 0 and 1
          printf("7| Exit Program\n");                    //7. Finish using program
          
          printf("\nPlease enter your choice:\t");           
          
          scanf("%d", &option); printf("\n"); 
          
          printf("%lf\n", p1);
          
          if (option==1);  
          else if (option==2);
          else if (option==3);
          else if (option==4);
          else if (option==5);
          else if (option==6);
          else if (option==7) 
          {
             printf ("Program terminated.\n\n");
             exit(1);
          }
          else printf ("You have entered an incorrect value, please enter a number from the menu only.\n");// Tells user if wrong number entered
          
       }
    }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Press the edit button on the bottom right corner and delete this repost.

    I know you did it cause Cprogramming was updating slowly and didn't realize you posted, so just go ahead and try to delete this.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	const int number_of_points = 10;
    	const int dimensions = 3;
    
    	int points[number_of_points][dimensions] = {0};
    
    	//row 0 in the array:
    	points[0][0] = 10;
    	points[0][1] = 20;
    	points[0][2] = 30;
    
    	//row 1 in the array:
    	points[1][0] = 5;
    	points[1][1] = 3;
    	points[1][2] = 7;
    
         return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21