Three geometric entities (a circle, a rectangle and a triangle) should be first randomized using rand function in line with srand(time(NULL)).
These three geometrric entities can/should be represented using the following C struct samples in your program:
Write three functions for each geometric entity that randomizes the geometric parameters (such as center X and Y coordinates and radius for a circle) and returns these geometries (such as struct Circle, struct Rectangle and struct Triangle). Note that floating numbers should be randmized from 0 to 10.
Ideas is simple to randomize the number using the range [0 10 ] an dwe use use the two random numbers in int to divide each other to get the same
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct Circle
{
double x;
double y;
double r;
};
struct Circle randomize_circle()
{
struct Circle c1;
double a=10;
/*here a=10 is the range from 0 to 10 upt0 which we
want to get the double values. as defined here.
since we cant get the direct random double values so
we find random int values in range of 0 to RAND_MAX
and then we divide it by RAND_MAX to get it in range of
[0 to 1] and then we multiply it with 10 to get the
to get it in range of [0 10]..
*/
c1.x= (double)(rand()*a)/(double)(RAND_MAX);
c1.y=(double)(rand()*a)/(double)(RAND_MAX);
c1.r=(double)(rand()*a)/(double)(RAND_MAX);
//assingn the random x ,y and return c1..
return c1;
}
//we have the rectangle as x y and x top and y top here as defined
struct rectangle
{
double xBottomLeft;
double yBottomLeft;
double xtopRight;
double ytopLeft;
};
struct rectangle randomize_rectangle()
{
struct rectangle r1;
double a=10.00;
r1.xBottomLeft=(double)(rand()*a)/(double)(RAND_MAX);
r1.yBottomLeft=(double)(rand()*a)/(double)(RAND_MAX);
r1.xtopRight=(double)(rand()*a)/(double)(RAND_MAX);
r1.ytopLeft=(double)(rand()*a)/(double)(RAND_MAX);
return r1;
}
struct Triangle
{
double x1;
double y1;
double x2;
double y2;
double x3;
double y3;
};
//we get the randomize_triangle and randomize_rectangle as defined...
struct Triangle randomize_triangle()
{
struct Triangle t1;
double a=10.00;
t1.x1=(double)(rand()*a)/(double)(RAND_MAX);
t1.y1=(double)(rand()*a)/(double)(RAND_MAX);
t1.x2=(double)(rand()*a)/(double)(RAND_MAX);
t1.y2=(double)(rand()*a)/(double)(RAND_MAX);
t1.x3=(double)(rand()*a)/(double)(RAND_MAX);
t1.y3=(double)(rand()*a)/(double)(RAND_MAX);
return t1;
}
int main(){
srand((unsigned int )time(NULL));
//we randomize_circle the teh rectangle and Triangle and get the rectangle
struct Circle c2= randomize_circle();
struct rectangle r2= randomize_rectangle();
struct Triangle t1=randomize_triangle();
return 0;
}
Note: in case of any query plz ask in comment section
Thank you
Keep learning.
Three geometric entities (a circle, a rectangle and a triangle) should be first randomized using rand...
please answer the second part first part answered. the answer to the first part is at the bottom bring the rest of the place HAVE TO BE SOLVED WİTH C PROGRAMMİNG A programming task is given in below (i.e., you are supposed to write a single program involving all 5 tasks in below). You should write a C program and upload your c/cpp file . Students are allowed to use MAK104E course (powerpoint) slights. 1) Three geometric entities (a circle,...
matlab 3. Filename: area2d.m The area of a triangle whose three vertices are points (x1, yı), (X2, y2), and (x3, y3) can be found using the absolute value of the following equation: A = 3 [x: (– yz) – x2\1 – yz) + x3V1 – Yz)] Write a MATLAB function area2d that calculates the area of a triangle using the following syntax: A = area2d (x,y) where x and y are vectors such that x = [X1, X2, X3] and...
Description There are 4 classes, Figure is the base class,both Triangle, Rectangle and Circle are all inherited from it. Figure class is like following: class FIGURE { public: void set_size(double x, double y = 0); virtual double get_area() = 0; protected: double x_size, y_size; }; You should implement Figure, Triangle, Rectange, Circle class. Output Area of triangle is 60 Area of rectangle is 120 Area of circle is 706.858 //Figure.h #ifndef FIGURE_H #define FIGURE_H const double PI = 3.14159; class...
GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public class DrawingFrame extends JFrame { JButton loadButton, saveButton, drawButton; JComboBox colorList, shapesList; JTextField parametersTextField; DrawingFrame() { super("Drawing Application"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true); toolbar.add(loadButton=new JButton("Load")); toolbar.add(saveButton=new JButton("Save")); toolbar.addSeparator(); toolbar.add(drawButton=new JButton("Draw")); toolbar.addSeparator(); toolbar.addSeparator(); toolbar.add(new...
Using python Here is the code import turtle def draw_triangle(vertex, length, k): ''' Draw a triangle at depth k given the bottom vertex. vertex: a tuple (x,y) that gives the coordinates of the bottom vertex. When k=0, vertex is the left bottom vertex for the outside triangle. length: the length of the original outside triangle (the biggest one). k: the depth of the input triangle. As k increases by 1, the triangles shrink to a smaller size. When k=0, the...
GUI bouncing shapes program use this interface the out put of the program should be a jFrame with three buttons: “add triangle”, “add square” and “add circle” and a blank screen. when the user clicks any of these buttons the corresponding shape appears and starts bouncing around the screen. the shape of these shaoes and randomized and anytime the user clicks the button you should be able to keeping adding shapes on the screen while the previosus shape is bouncing...
Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...