#include stdafx.h #include iostream using namespace std;vo.docx

A

#include stdafx.h #include iostream using namespace std;vo

#include <stdafx.h>
#include <iostream>
using namespace std;
void getdata(int& ident, int& grade_value);
void sortlist(int& ident, int& grade_value);
const int nil = 0;
class node_type // declaration of class//
{
public:
int id;
int grade;
node_type *next;
};
void getdata(int& ident, int& grade_value);
void sortlist(int& ident, int& grade_value);
const int nil = 0;
void main()
{
node_type *first, *p, *q, *newnode;
int i, ident, grade_value;
float sum, average;
sum = 0;
first = new node_type;
p = first;
getdata(ident, grade_value);
(*first).id = ident;
(*first).grade = grade_value;
(*first).next = nil;
for (i = 2; i <= 10; ++i)
{
getdata(ident, grade_value);
newnode = new node_type;
(*newnode).id = ident;
(*newnode).grade = grade_value;
(*newnode).next = nil;
//**********Links previous node to newnode******//
(*p).next = newnode;
p = newnode;
}
//**********Traverses list and prints out nodes in
chronological order ******//
q = first;
cout << "The list contains  ";
while (q != nil)
{
cout << "ID is :" << (*q).id << " ";
cout << "GRADE is :" << (*q).grade << " ";
sum = sum + (*q).grade;
q = (*q).next;
}
average = sum / 10;
cout << " The average of the grades is " << average << "
";
sortlist(ident, grade_value);
}
void getdata(int& ident, int& grade_value)
{
cout << "Enter id and grade  ";
cin >> ident;
cout << ident << " ";
cin >> grade_value;
cout << grade_value << " ";
}
void sortlist(int& ident, int& grade_value);
{
if (first == nil)
first = newnode;
else if ((*first).next == nil)
{
if ((*newnode).id > (*first).id)
(*first).next == newnode;
else
{
(*newnode).next = first;
first = newnode;
}
}
else if ((newnode).id < (*first).id)
(*newnode).next = first;
first = newnode;
else
q = first;
p = (*q).next;
while ((*p).id < (*newnode).id && ((*p).next != nil))
{
q = p;
p = (*p).next;
}
if ((*p).id >= (*newnode).id)
(*q).next = newnode;
(*newnode).next = p;
}
else
{
(*p).next = newnode;
}
}
Using the linked list program given in class , alter the
program to input 10 integers, sorting them
as they are inserted into the list. Print out the sorted
list.
Compute the average of the sorted values and print this
out.
Then delete all values from the list which are LESS than the
average of the entries in the list
Then create a second list of 10 integers, sorting as the
list
is created. Print out this list.
Finally, merge the two lists together (i.e. the ORIGINAL first
and second lists), eliminating any duplicates
Print out the final merged list.
Solution
Here is the modified code:
#include <stdafx.h>
#include <iostream>
using namespace std;
void getdata(int& ident, int& grade_value);
void sortlist(int& ident, int& grade_value);
const int nil = 0;
class node_type // declaration of class//
{
public:
int id;
int grade;
node_type *next;
};
void getdata(int& ident, int& grade_value);
void sortlist(int& ident, int& grade_value);
const int nil = 0;
void main()
{
const int NUM_NODES = 10 ; // number of nodes to be
added
int ident, grade_value;
getdata(ident, grade_value);
node_type* first = new node_type { ident, grade_value,
nullptr } ;
node_type* last = first; // last keeps track of the last ode i n
the list.
// right now, there is only one node and last
== first
for( int i = 1 ; i < NUM_NODES ; ++i ) // add
(NUM_NODES-1) more nodes
{
getdata(ident, grade_value);
node_type* newnode = new node_type { ident,
grade_value, nullptr } ;
last->next = newnode; // append newnode to the end of the
list:
last = newnode; // and the node just added at the end
becomes the last node
}
double sum = 0 ;
std::cout << "The list contains  ";
for( node_type* current = first ; current != nullptr ; current =
current->next )
{
// print out the id and grade in the current node
std::cout << "ID is : " << current->id << " GRADE is :
" << current->grade << ' ' ;
sum += current->grade ; // add the grade in the current
node
}
const double average = sum / NUM_NODES ;
std::cout << " The average of the grades is " << average <<
' ' ;
}
void getdata( int& ident, int& grade_value )
{
std::cout << "Enter id and grade  ";
std::cin >> ident;
std::cin >> grade_value;
}
void sortlist(int& ident, int& grade_value);
{
if (first == nil)
first = newnode;
else if ((*first).next == nil)
{
if ((*newnode).id > (*first).id)
(*first).next == newnode;
else
{
(*newnode).next = first;
first = newnode;
}
}
else if ((newnode).id < (*first).id)
(*newnode).next = first;
first = newnode;
else
q = first;
p = (*q).next;
while ((*p).id < (*newnode).id && ((*p).next !=
nil))
{
q = p;
p = (*p).next;
}
if ((*p).id >= (*newnode).id)
(*q).next = newnode;
(*newnode).next = p;
}
else
{
(*p).next = newnode;
}
}

Recomendados

C Homework Help por
C Homework HelpC Homework Help
C Homework HelpProgramming Homework Help
40 visualizações14 slides
Lab Week 2 Game Programming.docx por
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
18 visualizações13 slides
Please answer question only where it states -add code above this line.docx por
Please answer question only where it states -add code above this line.docxPlease answer question only where it states -add code above this line.docx
Please answer question only where it states -add code above this line.docxcgraciela1
3 visualizações1 slide
week-13x por
week-13xweek-13x
week-13xKITE www.kitecolleges.com
243 visualizações13 slides
include getopt in this code with the usage doublesort [-d] [-o out.pdf por
include getopt in this code with the usage  doublesort [-d] [-o out.pdfinclude getopt in this code with the usage  doublesort [-d] [-o out.pdf
include getopt in this code with the usage doublesort [-d] [-o out.pdfaggarwalenterprisesf
6 visualizações3 slides
Write java program using linked list to get integer from user and.docx por
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docxajoy21
3 visualizações6 slides

Mais conteúdo relacionado

Similar a #include stdafx.h #include iostream using namespace std;vo.docx

#include iostream using namespace std; const int nil = 0; cl.docx por
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docxajoy21
2 visualizações14 slides
DSA(1).pptx por
DSA(1).pptxDSA(1).pptx
DSA(1).pptxDaniyalAli81
5 visualizações36 slides
include getopt in this code with the usage doublesort d.pdf por
include getopt in this code with the usage  doublesort d.pdfinclude getopt in this code with the usage  doublesort d.pdf
include getopt in this code with the usage doublesort d.pdfadisainternational
4 visualizações2 slides
C code on linked list #include stdio.h #include stdlib.h.pdf por
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
2 visualizações4 slides
C program to insert a node in doubly linked list por
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
214 visualizações6 slides
- Using the linked list program given in class - alter the program t.docx por
- Using the linked list program given in class - alter the   program t.docx- Using the linked list program given in class - alter the   program t.docx
- Using the linked list program given in class - alter the program t.docxdorisc7
2 visualizações3 slides

Similar a #include stdafx.h #include iostream using namespace std;vo.docx(20)

#include iostream using namespace std; const int nil = 0; cl.docx por ajoy21
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
ajoy212 visualizações
DSA(1).pptx por DaniyalAli81
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
DaniyalAli815 visualizações
include getopt in this code with the usage doublesort d.pdf por adisainternational
include getopt in this code with the usage  doublesort d.pdfinclude getopt in this code with the usage  doublesort d.pdf
include getopt in this code with the usage doublesort d.pdf
adisainternational4 visualizações
C code on linked list #include stdio.h #include stdlib.h.pdf por deepua8
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
deepua82 visualizações
C program to insert a node in doubly linked list por Sourav Gayen
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
Sourav Gayen214 visualizações
- Using the linked list program given in class - alter the program t.docx por dorisc7
- Using the linked list program given in class - alter the   program t.docx- Using the linked list program given in class - alter the   program t.docx
- Using the linked list program given in class - alter the program t.docx
dorisc72 visualizações
Help I keep getting the same error when running a code. Below is the.pdf por mail931892
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail9318922 visualizações
FP 201 - Unit 6 por rohassanie
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
rohassanie776 visualizações
Implement the unsorted single linked list as we did in the class and .pdf por arihantstoneart
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
arihantstoneart2 visualizações
Linkedlist por Masud Parvaze
LinkedlistLinkedlist
Linkedlist
Masud Parvaze164 visualizações
dynamicList.ppt por ssuser0be977
dynamicList.pptdynamicList.ppt
dynamicList.ppt
ssuser0be9779 visualizações
17 linkedlist (1) por Himadri Sen Gupta
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta247 visualizações
#includeiostream #includecstdio #includecstdlib using na.pdf por harihelectronicspune
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune2 visualizações
Data structures cs301 power point slides lecture 03 por Nasir Mehmood
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood808 visualizações
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf por foottraders
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdfPLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf
foottraders2 visualizações
Write a program that accepts an arithmetic expression of unsigned in.pdf por JUSTSTYLISH3B2MOHALI
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI3 visualizações
Doublylinklist por ritu1806
DoublylinklistDoublylinklist
Doublylinklist
ritu18062.2K visualizações
Linked lists por George Scott IV
Linked listsLinked lists
Linked lists
George Scott IV267 visualizações
mainpublic class AssignmentThree {    public static void ma.pdf por fathimafancyjeweller
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller2 visualizações

Mais de ajoy21

Please complete table with answers; BUT ALSO, show step by step all .docx por
Please complete table with answers; BUT ALSO, show step by step all .docxPlease complete table with answers; BUT ALSO, show step by step all .docx
Please complete table with answers; BUT ALSO, show step by step all .docxajoy21
14 visualizações1 slide
Please check the syllabus for the following essays(I am done with th.docx por
Please check the syllabus for the following essays(I am done with th.docxPlease check the syllabus for the following essays(I am done with th.docx
Please check the syllabus for the following essays(I am done with th.docxajoy21
9 visualizações1 slide
Please choose from the following companies for Assignment 21. H.docx por
Please choose from the following companies for Assignment 21. H.docxPlease choose from the following companies for Assignment 21. H.docx
Please choose from the following companies for Assignment 21. H.docxajoy21
3 visualizações2 slides
Please complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docx por
Please complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docxPlease complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docx
Please complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docxajoy21
3 visualizações1 slide
PLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docx por
PLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docxPLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docx
PLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docxajoy21
3 visualizações2 slides
Please complete ModuleWeek 4 assignment Research Paper Abstract .docx por
Please complete ModuleWeek 4 assignment Research Paper Abstract .docxPlease complete ModuleWeek 4 assignment Research Paper Abstract .docx
Please complete ModuleWeek 4 assignment Research Paper Abstract .docxajoy21
3 visualizações1 slide

Mais de ajoy21(20)

Please complete table with answers; BUT ALSO, show step by step all .docx por ajoy21
Please complete table with answers; BUT ALSO, show step by step all .docxPlease complete table with answers; BUT ALSO, show step by step all .docx
Please complete table with answers; BUT ALSO, show step by step all .docx
ajoy2114 visualizações
Please check the syllabus for the following essays(I am done with th.docx por ajoy21
Please check the syllabus for the following essays(I am done with th.docxPlease check the syllabus for the following essays(I am done with th.docx
Please check the syllabus for the following essays(I am done with th.docx
ajoy219 visualizações
Please choose from the following companies for Assignment 21. H.docx por ajoy21
Please choose from the following companies for Assignment 21. H.docxPlease choose from the following companies for Assignment 21. H.docx
Please choose from the following companies for Assignment 21. H.docx
ajoy213 visualizações
Please complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docx por ajoy21
Please complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docxPlease complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docx
Please complete ModuleWeek 4 Discussion Board Forum 3 with a repl.docx
ajoy213 visualizações
PLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docx por ajoy21
PLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docxPLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docx
PLEASE AVOID CHANGING PRICE AFTER THE AGREEMENT IS SIGNED, THANK YOU.docx
ajoy213 visualizações
Please complete ModuleWeek 4 assignment Research Paper Abstract .docx por ajoy21
Please complete ModuleWeek 4 assignment Research Paper Abstract .docxPlease complete ModuleWeek 4 assignment Research Paper Abstract .docx
Please complete ModuleWeek 4 assignment Research Paper Abstract .docx
ajoy213 visualizações
Please complete outline to be used as guide for my assignment. For.docx por ajoy21
Please complete outline to be used as guide for my assignment. For.docxPlease complete outline to be used as guide for my assignment. For.docx
Please complete outline to be used as guide for my assignment. For.docx
ajoy213 visualizações
Please complete the assignment listed below.Define and explain, us.docx por ajoy21
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
ajoy214 visualizações
PLEASE COMPLETE ALL WORK IN DETAILDo work on a paper topic tha.docx por ajoy21
PLEASE COMPLETE ALL WORK IN DETAILDo work on a paper topic tha.docxPLEASE COMPLETE ALL WORK IN DETAILDo work on a paper topic tha.docx
PLEASE COMPLETE ALL WORK IN DETAILDo work on a paper topic tha.docx
ajoy212 visualizações
Please complete in professional detail with professional responses f.docx por ajoy21
Please complete in professional detail with professional responses f.docxPlease complete in professional detail with professional responses f.docx
Please complete in professional detail with professional responses f.docx
ajoy212 visualizações
PLEASE COMPLETE IN DETAIL AND PROVIDE SPECIFICS FOR AN INDIVIDUAL WH.docx por ajoy21
PLEASE COMPLETE IN DETAIL AND PROVIDE SPECIFICS FOR AN INDIVIDUAL WH.docxPLEASE COMPLETE IN DETAIL AND PROVIDE SPECIFICS FOR AN INDIVIDUAL WH.docx
PLEASE COMPLETE IN DETAIL AND PROVIDE SPECIFICS FOR AN INDIVIDUAL WH.docx
ajoy213 visualizações
Please complete the below assignments, attached are pages from the t.docx por ajoy21
Please complete the below assignments, attached are pages from the t.docxPlease complete the below assignments, attached are pages from the t.docx
Please complete the below assignments, attached are pages from the t.docx
ajoy214 visualizações
Please complete as two separate essay questions, in APA format.  No .docx por ajoy21
Please complete as two separate essay questions, in APA format.  No .docxPlease complete as two separate essay questions, in APA format.  No .docx
Please complete as two separate essay questions, in APA format.  No .docx
ajoy215 visualizações
Please carefully check the due timeyou have 10+hours to finish thi.docx por ajoy21
Please carefully check the due timeyou have 10+hours to finish thi.docxPlease carefully check the due timeyou have 10+hours to finish thi.docx
Please carefully check the due timeyou have 10+hours to finish thi.docx
ajoy213 visualizações
please check the folloing due today and in 935 Call a local met.docx por ajoy21
please check the folloing due today and in 935 Call a local met.docxplease check the folloing due today and in 935 Call a local met.docx
please check the folloing due today and in 935 Call a local met.docx
ajoy213 visualizações
Please check the attachment for my paper.Please add citations to a.docx por ajoy21
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
ajoy212 visualizações
Please carefully review the information in Chapter 2 relative to wha.docx por ajoy21
Please carefully review the information in Chapter 2 relative to wha.docxPlease carefully review the information in Chapter 2 relative to wha.docx
Please carefully review the information in Chapter 2 relative to wha.docx
ajoy214 visualizações
Please choose one of the following questions and write a paper of up.docx por ajoy21
Please choose one of the following questions and write a paper of up.docxPlease choose one of the following questions and write a paper of up.docx
Please choose one of the following questions and write a paper of up.docx
ajoy214 visualizações
Please build a cultural metaphor for a country besides the United St.docx por ajoy21
Please build a cultural metaphor for a country besides the United St.docxPlease build a cultural metaphor for a country besides the United St.docx
Please build a cultural metaphor for a country besides the United St.docx
ajoy214 visualizações
Please be sure you can deliver a quality response, mantain  honework.docx por ajoy21
Please be sure you can deliver a quality response, mantain  honework.docxPlease be sure you can deliver a quality response, mantain  honework.docx
Please be sure you can deliver a quality response, mantain  honework.docx
ajoy213 visualizações

Último

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE... por
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...Nguyen Thanh Tu Collection
71 visualizações91 slides
Six Sigma Concept by Sahil Srivastava.pptx por
Six Sigma Concept by Sahil Srivastava.pptxSix Sigma Concept by Sahil Srivastava.pptx
Six Sigma Concept by Sahil Srivastava.pptxSahil Srivastava
40 visualizações11 slides
Meet the Bible por
Meet the BibleMeet the Bible
Meet the BibleSteve Thomason
76 visualizações80 slides
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf por
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdfSTRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdfDr Vijay Vishwakarma
90 visualizações68 slides
11.30.23A Poverty and Inequality in America.pptx por
11.30.23A Poverty and Inequality in America.pptx11.30.23A Poverty and Inequality in America.pptx
11.30.23A Poverty and Inequality in America.pptxmary850239
86 visualizações18 slides
MIXING OF PHARMACEUTICALS.pptx por
MIXING OF PHARMACEUTICALS.pptxMIXING OF PHARMACEUTICALS.pptx
MIXING OF PHARMACEUTICALS.pptxAnupkumar Sharma
117 visualizações35 slides

Último(20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE... por Nguyen Thanh Tu Collection
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
Nguyen Thanh Tu Collection71 visualizações
Six Sigma Concept by Sahil Srivastava.pptx por Sahil Srivastava
Six Sigma Concept by Sahil Srivastava.pptxSix Sigma Concept by Sahil Srivastava.pptx
Six Sigma Concept by Sahil Srivastava.pptx
Sahil Srivastava40 visualizações
Meet the Bible por Steve Thomason
Meet the BibleMeet the Bible
Meet the Bible
Steve Thomason76 visualizações
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf por Dr Vijay Vishwakarma
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdfSTRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf
Dr Vijay Vishwakarma90 visualizações
11.30.23A Poverty and Inequality in America.pptx por mary850239
11.30.23A Poverty and Inequality in America.pptx11.30.23A Poverty and Inequality in America.pptx
11.30.23A Poverty and Inequality in America.pptx
mary85023986 visualizações
MIXING OF PHARMACEUTICALS.pptx por Anupkumar Sharma
MIXING OF PHARMACEUTICALS.pptxMIXING OF PHARMACEUTICALS.pptx
MIXING OF PHARMACEUTICALS.pptx
Anupkumar Sharma117 visualizações
UNIDAD 3 6º C.MEDIO.pptx por MarcosRodriguezUcedo
UNIDAD 3 6º C.MEDIO.pptxUNIDAD 3 6º C.MEDIO.pptx
UNIDAD 3 6º C.MEDIO.pptx
MarcosRodriguezUcedo145 visualizações
NodeJS and ExpressJS.pdf por ArthyR3
NodeJS and ExpressJS.pdfNodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdf
ArthyR347 visualizações
ANGULARJS.pdf por ArthyR3
ANGULARJS.pdfANGULARJS.pdf
ANGULARJS.pdf
ArthyR349 visualizações
Education of marginalized and socially disadvantages segments.pptx por GarimaBhati5
Education of marginalized and socially disadvantages segments.pptxEducation of marginalized and socially disadvantages segments.pptx
Education of marginalized and socially disadvantages segments.pptx
GarimaBhati540 visualizações
Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37 por MysoreMuleSoftMeetup
Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37
Payment Integration using Braintree Connector | MuleSoft Mysore Meetup #37
MysoreMuleSoftMeetup44 visualizações
MercerJesse3.0.pdf por jessemercerail
MercerJesse3.0.pdfMercerJesse3.0.pdf
MercerJesse3.0.pdf
jessemercerail92 visualizações
INT-244 Topic 6b Confucianism por S Meyer
INT-244 Topic 6b ConfucianismINT-244 Topic 6b Confucianism
INT-244 Topic 6b Confucianism
S Meyer44 visualizações
Create a Structure in VBNet.pptx por Breach_P
Create a Structure in VBNet.pptxCreate a Structure in VBNet.pptx
Create a Structure in VBNet.pptx
Breach_P82 visualizações
MercerJesse2.1Doc.pdf por jessemercerail
MercerJesse2.1Doc.pdfMercerJesse2.1Doc.pdf
MercerJesse2.1Doc.pdf
jessemercerail301 visualizações
Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv... por Taste
Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv...Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv...
Creative Restart 2023: Leonard Savage - The Permanent Brief: Unearthing unobv...
Taste53 visualizações
Berry country.pdf por MariaKenney3
Berry country.pdfBerry country.pdf
Berry country.pdf
MariaKenney361 visualizações
EILO EXCURSION PROGRAMME 2023 por info33492
EILO EXCURSION PROGRAMME 2023EILO EXCURSION PROGRAMME 2023
EILO EXCURSION PROGRAMME 2023
info33492181 visualizações

#include stdafx.h #include iostream using namespace std;vo.docx

  • 1. #include <stdafx.h> #include <iostream> using namespace std; void getdata(int& ident, int& grade_value); void sortlist(int& ident, int& grade_value); const int nil = 0; class node_type // declaration of class// { public: int id; int grade; node_type *next; }; void getdata(int& ident, int& grade_value); void sortlist(int& ident, int& grade_value); const int nil = 0; void main() { node_type *first, *p, *q, *newnode; int i, ident, grade_value; float sum, average; sum = 0; first = new node_type; p = first; getdata(ident, grade_value); (*first).id = ident; (*first).grade = grade_value; (*first).next = nil; for (i = 2; i <= 10; ++i) { getdata(ident, grade_value); newnode = new node_type; (*newnode).id = ident; (*newnode).grade = grade_value; (*newnode).next = nil;
  • 2. //**********Links previous node to newnode******// (*p).next = newnode; p = newnode; } //**********Traverses list and prints out nodes in chronological order ******// q = first; cout << "The list contains "; while (q != nil) { cout << "ID is :" << (*q).id << " "; cout << "GRADE is :" << (*q).grade << " "; sum = sum + (*q).grade; q = (*q).next; } average = sum / 10; cout << " The average of the grades is " << average << " "; sortlist(ident, grade_value); } void getdata(int& ident, int& grade_value) { cout << "Enter id and grade "; cin >> ident; cout << ident << " "; cin >> grade_value; cout << grade_value << " "; } void sortlist(int& ident, int& grade_value); { if (first == nil) first = newnode; else if ((*first).next == nil) {
  • 3. if ((*newnode).id > (*first).id) (*first).next == newnode; else { (*newnode).next = first; first = newnode; } } else if ((newnode).id < (*first).id) (*newnode).next = first; first = newnode; else q = first; p = (*q).next; while ((*p).id < (*newnode).id && ((*p).next != nil)) { q = p; p = (*p).next; } if ((*p).id >= (*newnode).id) (*q).next = newnode; (*newnode).next = p; } else { (*p).next = newnode; } }
  • 4. Using the linked list program given in class , alter the program to input 10 integers, sorting them as they are inserted into the list. Print out the sorted list. Compute the average of the sorted values and print this out. Then delete all values from the list which are LESS than the average of the entries in the list Then create a second list of 10 integers, sorting as the list is created. Print out this list. Finally, merge the two lists together (i.e. the ORIGINAL first and second lists), eliminating any duplicates Print out the final merged list. Solution Here is the modified code: #include <stdafx.h> #include <iostream> using namespace std; void getdata(int& ident, int& grade_value); void sortlist(int& ident, int& grade_value); const int nil = 0; class node_type // declaration of class//
  • 5. { public: int id; int grade; node_type *next; }; void getdata(int& ident, int& grade_value); void sortlist(int& ident, int& grade_value); const int nil = 0; void main() { const int NUM_NODES = 10 ; // number of nodes to be added int ident, grade_value; getdata(ident, grade_value); node_type* first = new node_type { ident, grade_value, nullptr } ; node_type* last = first; // last keeps track of the last ode i n the list. // right now, there is only one node and last == first for( int i = 1 ; i < NUM_NODES ; ++i ) // add (NUM_NODES-1) more nodes { getdata(ident, grade_value);
  • 6. node_type* newnode = new node_type { ident, grade_value, nullptr } ; last->next = newnode; // append newnode to the end of the list: last = newnode; // and the node just added at the end becomes the last node } double sum = 0 ; std::cout << "The list contains "; for( node_type* current = first ; current != nullptr ; current = current->next ) { // print out the id and grade in the current node std::cout << "ID is : " << current->id << " GRADE is : " << current->grade << ' ' ; sum += current->grade ; // add the grade in the current node } const double average = sum / NUM_NODES ; std::cout << " The average of the grades is " << average << ' ' ; } void getdata( int& ident, int& grade_value ) { std::cout << "Enter id and grade ";
  • 7. std::cin >> ident; std::cin >> grade_value; } void sortlist(int& ident, int& grade_value); { if (first == nil) first = newnode; else if ((*first).next == nil) { if ((*newnode).id > (*first).id) (*first).next == newnode; else { (*newnode).next = first; first = newnode; } } else if ((newnode).id < (*first).id) (*newnode).next = first; first = newnode; else q = first; p = (*q).next; while ((*p).id < (*newnode).id && ((*p).next != nil))
  • 8. { q = p; p = (*p).next; } if ((*p).id >= (*newnode).id) (*q).next = newnode; (*newnode).next = p; } else { (*p).next = newnode; } }