please refer below C++ code
#include<stdlib.h>
#include<stdio.h>
typedef struct point
{
int x;
int y;
struct point *next;
}point;
//adding node to linked list
void add_node(point **head, point *node)
{
if(*head == NULL)
*head = node;
else
{
point *temp = *head;
while(temp->next != NULL)
temp = temp->next;
temp->next = node;
}
}
//squaring distance from origin
void square_distance(point *head)
{
point *temp = head;
int dist;
while(temp != NULL)
{
dist = (temp->x * temp->x) + (temp->y * temp->y);
//distance from origin
printf("%d\n", dist);
temp = temp->next;
}
}
int main()
{
int x,y;
point *head = NULL;
point *temp;
while(1) //infinite loop to scan infinite lines
{
scanf("%d %d", &x,&y);
if(x==0 && y ==0)
break;
temp = new point; //creating node
temp->x = x; //setting x field
temp->y = y; //setting y field
temp->next = NULL;
add_node(&head,temp);
}
printf("\n\n");
square_distance(head);
return 0;
}
please refer below output
5 6
4 4
1 3
1 0
0 2
-1 2
-2 0
0 -4
3 -1
0 0
61
32
10
1
4
5
4
16
10
Process returned 0 (0x0) execution time : 44.080 s
Press any key to continue.
In this exercise, you will make a struct that contains x and y coordinates: struct point...
Write a complete program that: 1) declares two local integers x and y 2) defines a global structure containing two pointers (xptr,yptr) and an integer (z) 3) Declares a variable (mst) by the type of previous structure 4) requests the values of x and y from the user using only one scanf statement 5) sets the first pointer in the struct to point to x 6) sets the second pointer in the struct to point to y 7) uses the...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...
Please need help, programming in C
- Part A You will need to create a struct called Team that contains a string buffer for the team name. After you've defined 8 teams, you will place pointers to all 8 into an array called leaguel], defined the following way: Team leaguel8]. This must be an aray of pointers to teams, not an array of Teams Write a function called game) that takes pointers to two teams, then randomly and numerically determines...
3. Polar Coordinates. (a) Given a rectangular coordinate point (x, y), how do you compute the equivalent polar coordinates: (r, 0)? (b) Given a polar coordinate (r, o), how do you compute the equivalent rectangular coordinate: (x, y)? (c) Consider the drawing in Figure 1. Compute the coordinate of each small circle. (d) What if the circle is centered at the point (cx, cy) (and not the origin). How does the formula change?
14. p contains the elements 66, 9, 14, 52, 87, 14 and 17, in that order. Consider running the following line of code: p = question4(p); where question4 is the function defined below. Show the contents of p after the function call. struct node* question4(struct node *list) { struct node* a = list; struct node* b = list; struct node* c; if (a == NULL) return NULL; while ( a->next != NULL) a = a ->next; a->next = b; c...
14. p contains the elements 66, 9, 14, 52, 87, 14 and 17, in that order. Consider running the following line of code: p = question4(p); where question4 is the function defined below. Show the contents of p after the function call. struct node* question4(struct node *list) { struct node* a = list; struct node* b = list; struct node* c; if (a == NULL) return NULL; while ( a->next != NULL) a = a ->next; a->next = b; c...
Project 4 simulation with conway's rules for life - revisited due before 4/30 11:59pm, autograded by project 4 zylab, limited to 10 submissions. We will be using the concepts from project 2 to test the more recent concepts of linked lists, pointers, and file I/O. The initial data points will be stored in a file (specification of the layout of the file below), each grid of values will be dynamically allocated and then referenced via a pointer in a linked...
C++
Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...