1. Struct (Optional: 1 point) 1) Use the following abstract data type called Rectangle to get the length and width from the user. 2) Display the length, width, area, perimeter, and whether the rectangle is a square. struct Rectangle { float length; float width; float area; float perimeter; }; 2. Linked List (Optional: 1 point) Modify the following program to make a node containing data values of int, char, and string: #include using namespace std; struct Node { int data; struct Node *next; }; struct Node* head = nullptr; //or NULL or 0; void insert(int new_data) { struct Node* new_node = (struct Node*) new (struct Node); new_node->data = new_data; new_node->next = head; head = new_node; } void display() { struct Node* ptr; ptr = head; while (ptr != NULL) { cout<< ptr->data <<" "; ptr = ptr->next; } } int main() { insert(2); display(); return 0; }
1. Struct (Optional: 1 point) 1) Use the following abstract data type called Rectangle to get the length and width from the user. 2) Display the length, width, area, perimeter, and whether the rectangle is a square. struct Rectangle { float length; float width; float area; float perimeter; }; 2. Linked List (Optional: 1 point) Modify the following program to make a node containing data values of int, char, and string: #include using namespace std; struct Node { int data; struct Node *next; }; struct Node* head = nullptr; //or NULL or 0; void insert(int new_data) { struct Node* new_node = (struct Node*) new (struct Node); new_node->data = new_data; new_node->next = head; head = new_node; } void display() { struct Node* ptr; ptr = head; while (ptr != NULL) { cout<< ptr->data <<" "; ptr = ptr->next; } } int main() { insert(2); display(); return 0; }
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
1. Struct (Optional: 1 point)
1) Use the following abstract data type called Rectangle to get the length and width from
the user.
2) Display the length, width, area, perimeter, and whether the rectangle is a square.
struct Rectangle
{
float length;
float width;
float area;
float perimeter;
};
2. Linked List (Optional: 1 point)
Modify the following program to make a node containing data values of int, char, and string:
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *next;
};
struct Node* head = nullptr; //or NULL or 0;
void insert(int new_data)
{
struct Node* new_node = (struct Node*) new (struct Node);
new_node->data = new_data;
new_node->next = head;
head = new_node;
}
void display()
{
struct Node* ptr;
ptr = head;
while (ptr != NULL)
{
cout<< ptr->data <<" ";
ptr = ptr->next;
}
}
int main()
{
insert(2);
display();
return 0;
}
1) Create a linked list of ten nodes (each node contains the three types of data values).
2) Display the data values from the linked list.
3. Linked List in both directions (Optional: 1 point)
Modify the program from Question #2 so that your program displays the data values from
the linked list in both forward and reverse directions.
1) Use the following abstract data type called Rectangle to get the length and width from
the user.
2) Display the length, width, area, perimeter, and whether the rectangle is a square.
struct Rectangle
{
float length;
float width;
float area;
float perimeter;
};
2. Linked List (Optional: 1 point)
Modify the following program to make a node containing data values of int, char, and string:
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *next;
};
struct Node* head = nullptr; //or NULL or 0;
void insert(int new_data)
{
struct Node* new_node = (struct Node*) new (struct Node);
new_node->data = new_data;
new_node->next = head;
head = new_node;
}
void display()
{
struct Node* ptr;
ptr = head;
while (ptr != NULL)
{
cout<< ptr->data <<" ";
ptr = ptr->next;
}
}
int main()
{
insert(2);
display();
return 0;
}
1) Create a linked list of ten nodes (each node contains the three types of data values).
2) Display the data values from the linked list.
3. Linked List in both directions (Optional: 1 point)
Modify the program from Question #2 so that your program displays the data values from
the linked list in both forward and reverse directions.
4. Using the style of Object-Oriented programming (OOP) to create or instantiate three
Rectangle objects or instances with different sizes (Optional: 2 point). You may start with
the following class definition or something else you prefer.
class Rectangle
{
private:
double width;
double length;
public:
void setWidth(double);
void setLength(double);
double getWidth();
double getLength();
double getArea();
};
Rectangle objects or instances with different sizes (Optional: 2 point). You may start with
the following class definition or something else you prefer.
class Rectangle
{
private:
double width;
double length;
public:
void setWidth(double);
void setLength(double);
double getWidth();
double getLength();
double getArea();
};
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 4 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY