C++ Program
1. Read data for names and weights for 15 people.
2. Your program will build a list for the data maintained in ascending order based on both name and weight via a doubly linked list.
3. This dll will use one pointer to keep weights in sorted order, and use the other link to keep names on sorted order.
4. You need to build the list as you go maintaining this ordering, so at any time a print method was called it would print the related field in order. (This means nodes are added to the list in sorted order, elements are not added to the list followed by a sort called on the list.)
For example after 3 elements are added for (Name – Weight):
Michael – 275, Tom – 150, Abe – 200.
Output:
Names & weights sorted(ascending) by name. : Abe – 200, Michael – 275, Tom - 150
Names & weights sorted(ascending) by weight. : Tom – 150, Abe – 200, Michael - 275
#include<bits/stdc++.h>
using namespace std;
struct node
{
string name;
int weight;
node* next_for_name;
node* next_For_weight;
};
void add_to_list(string n,int w,node** head_for_name,node**
head_for_weight)
{
node* temp=new node;
temp ->name=n;
temp ->weight=w;
temp ->next_For_weight=NULL;
temp ->next_for_name=NULL;
node* t_head=(*head_for_name);
if(t_head==NULL) (*head_for_name)=temp;
else
{
node* prev=NULL;
while(t_head!=NULL && t_head ->name<n)
{
prev=t_head;
t_head=t_head ->next_for_name;
}
if(t_head==(*head_for_name))
{
temp->next_for_name=(*head_for_name);
(*head_for_name)=temp;
}
else
{
prev ->next_for_name=temp;
temp ->next_for_name=t_head;
}
}
t_head=*head_for_weight;
if(t_head==NULL) (*head_for_weight)=temp;
else
{
node *prev=NULL;
while(t_head!=NULL && t_head ->weight<w)
{
prev=t_head;
t_head=t_head ->next_For_weight;
}
if(t_head==(*head_for_weight))
{
temp->next_For_weight=(*head_for_weight);
(*head_for_weight)=temp;
}
else
{
prev ->next_For_weight=temp;
temp ->next_For_weight=t_head;
}
}
}
void print_list(node *head_for_name,node *head_for_weight)
{
cout<<"IN SORTED ORDER BY NAME"<<endl;
while(head_for_name!=NULL)
{
cout<<"NAME:"<<head_for_name->name<<"
WEIGHT:"<<head_for_name->weight<<endl;
head_for_name=head_for_name->next_for_name;
}
cout<<endl<<"IN SORTED ORDER BY
WEIGHT"<<endl;
while(head_for_weight!=NULL)
{
cout<<"NAME:"<<head_for_weight->name<<"
WEIGHT:"<<head_for_weight->weight<<endl;
head_for_weight=head_for_weight->next_For_weight;
}
cout<<endl;
}
int main()
{
string name;
int weight;
node* head_for_name=NULL;
node* head_for_weight=NULL;
for(int i=0;i<15;i++)
{
cout<<"Enter name and weight of person "<<i+1<<":
";
cin>>name;
cin>>weight;
add_to_list(name,weight,&head_for_name,&head_for_weight);
print_list(head_for_name,head_for_weight);
}
}
snapshot:


![head_for_name head_for_name->next_for_name; cout<<endl<<IN SORTED ORDER BY WEIGHT<<endl; while(head_for_weight] =NULL) cout](http://img.homeworklib.com/questions/50fa0840-4e29-11ec-a901-611661023e86.png?x-oss-process=image/resize,w_560)
OUTPUT:
C++ Program 1. Read data for names and weights for 15 people. 2. Your program will...
C++ Program 1. Read data for names and weights for 15 people. 2. Your program will build a list for the data maintained in ascending order based on both name and weight via a doubly linked list. 3. This dll will use one pointer to keep weights in sorted order, and use the other link to keep names on sorted order. 4. You need to build the list as you go maintaining this ordering, so at any time a print...
Help in JAVA please Write a program that reads a list of students (first names only) from a file. It is possible for the names to be in unsorted order in the file but they have to be placed in sorted order within the linked list. The program should use a doubly linked list. Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a pointer to the previous student. Here...
3. Name Search Modify the Sorted Names program that you wrote for exercises #2 so it allows you to search the array for a specific name. design a flowchart for it exercises 2 is as follow: Sorted Names Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents. Pseudocode for number 3 as follow: Initialize i=0 Get the name to search for If i<20...
.Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...
Do WITHOUT #include<sstream> C++ You are to write a program that will read in upto 15 names, rearrange each person's name. The list has been collected from different places and the names are not in some standard format. A person's last name may appear last or it may appeaer first. A label has been associated with each name to identify where the last name appears. Either "surname" or "lastname" appears just before a person's last name. The other will be...
I just need an algorithm for this please! I have C++ code for
it but I dont know how to creat an algorithm ..
CSE 1311-Project 4 Part I: Create and print out the two arrays: (Be sure to do this first) You are allowed to hard code these arrays into your program. You can also put the data into a file and read the information into the program. The data is as follows: 150 250 Anne Bob Ralph 305...
Please help!!
(C++ PROGRAM)
You will design an online contact list to keep track of names
and phone numbers.
·
a. Define a class contactList that can store a name and up to 3
phone numbers (use an array for the phone numbers). Use
constructors to automatically initialize the member variables.
b.Add the following operations to your program:
i. Add a new contact. Ask the user to enter the name and up to 3
phone numbers.
ii. Delete a contact...
Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold a user-defined number of test scores and student names, using parallel arrays. After student names and corresponding scores are entered, the array(s) should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score for the group (do not include the lowest score in the calculation of average grade). The program should display the...
Write a program in C++ to: 1. Read up to 10 names and 10 test scores from the keyboard (provide a method to end the input) (2 points); 2. print out the names and scores in a two column format (2 points); 3. use the function sort (you have to develop one) to sort the list according to test scores(4 points); 4. print out the sorted names and scores in a two column format (2 points)
read it carefully C++
Question: Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not...