Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8996719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:47:32+00:00 2026-06-15T23:47:32+00:00

Here is the problem I have, please don’t beat me up if I don’t

  • 0

Here is the problem I have, please don’t beat me up if I don’t explain it well or the code is of bad quality – I have only done about 2 weeks of C++ so far.

Explanation: I would like to build a structure (a structure might not be the best decision but I have to start somewhere) that will contain coordinates (x and y only) of a set of points (let’s call the set an arc), set id (and possibly other fields). Each set (arc) can contain various numbers of points.
I have implemented each point in the set (arc) as the class, then my arc structure contains various instanses of this class in a vector (along with other stuff).

Example of an arc structure:

Struc1:

Id (int) 1

xY (vector) (0;0) (1;1) (2;2)

Struc2:

Id (int) 2

xY (vector) (1;1) (4;4)

Problem:
I can’t figure out how to access elements within my arc structure: for example if I need to access the coordinates of the second point in the struc with Id 1, I would want Struc1.xY[1], however this doesn’t work as my code (below) stands.
I have found this post that explains how one could print values inside the struct, but I will need to access these elements to (later on) conditionally edit those coordinates. How can this be impemented?

My attempt: (EDITED)

#include <cmath>
#include <vector>
#include <cstdlib> 
#include <stdio.h>
#include <iostream>

using namespace std;

class Point
  {
  public:
      Point();
      ~Point(){ }

      void setX (int pointX) {x = pointX; }
      void setY (int pointY) {y = pointY; }
      int getX() { return x; }
      int getY() { return y; }

  private:
      int x;
      int y;
  }; 

Point::Point()
    {
        x = 0;
    y = 0;
    }

struct arc {
  int id;
  vector<Point> xY;
};

int main(){

  arc arcStruc;
  vector<Point> pointClassVector;
  int Id;
  int X;
  int Y;
  // other fields go here

  arc *a;

  int m = 2; // Just create two arcs for now
  int k = 3; // each with three points in it
  for (int n=0; n<m; n++){    
    a = new arc;
    Id = n+1;
    arcStruc.id = Id;
    Point pt;
    for (int j=0; j<k; j++){            
      X = n-1;
      Y = n+1;      
      pt.setX(X);
      pt.setY(Y);
      arcStruc.xY.push_back(pt);

    }
  }

for (vector<Point>::iterator it = arcStruc.xY.begin(); it != arcStruc.xY.end(); ++it)
  {
    cout << arcStruc.id.at(it);
    cout << arcStruc.xY.at(it);
  }

  delete a;  
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:47:33+00:00Added an answer on June 15, 2026 at 11:47 pm

    A couple of suggestions:

    • Don’t bother with the separate pointClassVector, just create and instead the Point objects straight into arcStruc.xY by using arcStruc.xY.push_back(). The line arcStruc.xY = pointClassVector triggers a copy of the whole vector, that’s a bit of a waste of CPU cycles.
    • There is absolutely no need to try and create a Point object on the heap, all that does is add complexity. Just use Point pt; and call the set functions on it – although I personally would do away with the set functions altogether and manipulate the data in Point directly, there is no need for the getters/setters and they don’t buy you anything. If this was my code, I’d write the point constructor to take x and y as parameters, that saves you an awful lot of unnecessary code. You also don’t need to provide an implementation for the destructor, the compiler generated one is fine.

    If you want to iterate through the vector, you should probably use iterators instead of attempting to index into the container. Either way, you can access arcStruc.xY to get its size and then access the elements individually using the [] operator or using iterators, like so:

     for (vector<Point>::iterator it = arcStruc.xY.begin(); it != arcStruc.xY.end(), ++it)
     {
        ... do something with it here, it can be derefernced to get at the Point structure ...
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am new here. i have a slight problem; PLease look at the following code
I have problem adding arraylist to list view, will explain about my problem here..
First, sorry for my bad english, I'm French. Here the problem : I have
This is another stab into a problem I posted here . Please don't close
I hope you can help me with a problem; first, please don't worry about
Please don't close this question before read my actual problem. I have seen many
Right, please don't point me there: Disable a HyperLink from code behind My problem
Please don't be deterred by the just another IE problem. I have a custom
Here is the problem: I have two columns in a table that, for each
Here's the problem: I have a data-bound list of items, basically a way for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.