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 9086735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:33:40+00:00 2026-06-16T21:33:40+00:00

Could you help me organize a dynamic array of points? I have coped with

  • 0

Could you help me organize a dynamic array of points?

I have coped with a dynamic array of integers. But I don’t know
how to organize it with structures.

Here is my code so far…

#include "stdafx.h"
#include <cstdlib>;
#include <iostream>;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
  int i = 0; // Array index.
  struct Point
  {
    int x;
    int y;
  };
  size_t n = sizeof(int);
  int * points = static_cast<int*>(malloc(n));
  char command;
  do
  {
    cout << "n - Create new point." << endl;
    cout << "q - Quit." << endl;
    cout << "Input a new command: ";
    cin >> command;
    if (command == 'n')
    {
      points[i] = 1;
      i++;
      /* points[i] = new Point();
         points[i].x = 1;
         points[i].y = 1; */
      // cout<<"("<<point1.x<<","<<point1.y<<")";               
    }               
    else if (command == 'q')
    {       
      for (int j = 0; j < i; j++)
        cout << points[j] <<endl;
      system("pause");
      return 0;
    }
    else
    {
      cout << "Please, enter a correct command." << endl << endl << endl;               
    }
  } while (true);
  system("pause");  
  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-16T21:33:41+00:00Added an answer on June 16, 2026 at 9:33 pm

    You can use vectors as @iedoc suggested:

    #include <iostream>;
    #include <vector>;
    
    using namespace std;
    
    struct SPoint
    {
        int X;
        int Y;
    };
    
    int main()
    {
        vector<SPoint> points;
    
        char command;
        do
        {
            cout << "n - Create new point." << endl;
            cout << "q - Quit." << endl;
            cout << "Input a new command: ";
    
            cin >> command;
    
            if (command == 'n')
            {
                int x = 0;
                int y = 0;
    
                cout << "X: ";
                cin >> x;
    
                cout << "Y: ";
                cin >> y;
    
                SPoint point = { x, y};
                points.push_back(point);
            }
    
            else if (command == 'q')
            {
                for (int i = 0; i < points.size(); ++i)
                {
                    cout << "(" << points[i].X << "," << points[i].Y << ")";
                }
    
                return 0;
            }
            else
            {
                cout << "Please, enter a correct command."<<endl<<endl<<endl;
            }
        }
    
        while(true);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What could help me in helping writing highly compact(least byte code count) programs in
Wondering if someone could help me. I have next to no knowledge with Ajax,
Hope someone could help me with this: I would like to have a column
Anyone could help me with a mysql Question? I have a row with a
Ok I have this code: <? $name=$_POST['name']; $con = mysql_connect(localhost,root,); if (!$con) { die('Could
I could really your help! I need to sum a dynamic amount of textboxes
I was hoping someone could help me with the following script: jQuery(document).ready(function($) { $(.infoBoxBtn
I hope you could help me. I' m using QT and try to do
was hoping you could help me out. I am trying to check if a
I was hoping someone could help me with submitting the answers to an HTML

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.