Write your question here.
Hi, for an assignment I have been asked to plot a set of random points in the cout. I am not supposed to use any graphing library.
I will have to write a code that generates a number of points based on user input ( for example if user inputs 20 it creates 20 random points) that ranges from x[0,100]and y[0,100]. After that those points are to be shown in the cout console.
this code is to be written with basic c++ syntax. No graphing library can be used. after that I am asked to find the centroid of the points assuming the points create simple polygon.
I have no idea how to start this code.
Any help is helpful.
vector<vector<char> > plane
I realize this is the way i can get two numbers to determine one point but how will that lead to plotting in console.
If you want to use a 2D array/vector, that is a good start. If you're a beginner, using a 2D array might be easier just due to its simpler syntax, but anyway:
To fill any 2D array, the most common way is to use two for loops. I don't wan to show you everything, but here is a good start...
#include <cstdlib>
#include <iostream>
//declare 2D array variable
//If you need to use a 2D vector, look up in a tutorial how to correctly initialize a 2D one.
...
/*would need to be 100x100 array */
for (int i = 0; i < OuterArraySize; i++)
{
for (int j = 0; j < InnerArraySize; j++)
{
int rand_value_x = rand()%101; // This produces a number between [0, 100].
int rand_value_y = rand()%101;
//assign a char value to the array at array[rand_x][rand_y] if you don't already have 20 values
//otherwise assign a space ' ' char
}
}
//printing:
//do another 2x next For loop to display
//add a newline after each inner for loop so it doesn't keep writing to the same file.