lTele2 LTE C 21:44 21:44 iCloud [] iCloud corresponding message implement the se
ID: 3600070 • Letter: L
Question
lTele2 LTE C 21:44 21:44 iCloud [] iCloud corresponding message implement the second version of the program, instead of the array use a doubly linked list ;elements are added in such a way that the list ordering by by group number is number is preserved (inserting a new element after an element that is smaller than a new element and in front of a large element. Write the program in c++ and show me a example of output please General requirements 1.use lines of type char (dynamic,new,or static char[N],it is recommended to use stein functions from the library 2.dynamic data structure (list) is created by the student independently, it is forbidden to use ready-made solutions. Solutions Describe a structure named student containing the following fields full name group number performance in 5 subjects(an array of grades) Write a program that does the following keyboard input of data into an array consisting of a maximum ,making it possible to interrupt the input so that you can not Enter all 10 elements; after the input is finished ,sort the array elements in ascending order of the group number output to the console of the names and initials of all students included in the array ,of the student's average score is more than 4.0; if there are no such students ,output a corresnondina messageExplanation / Answer
1)
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#define MAX 100
using namespace std;
// Main function definition
int main()
{
// Character array
char characterArray[100];
// Pointer created using malloc() function
char *pointerMalloc = (char *)malloc(sizeof(char));
// Pointer created using new
char *pointerNew = new char[sizeof(char)];
// Accept data
cout<<" Enter a string to check pointer using malloc(): ";
cin.getline(pointerMalloc, 10);
// Clears standard input
fflush(stdin);
// Displays data
cout<<" Data entered (using malloc()): "<<pointerMalloc;
// Accept data
cout<<" Enter a string to check pointer using new: ";
cin.getline(pointerNew, 100);
// Clears standard input
fflush(stdin);
// Displays data
cout<<" Data entered (using new): "<<pointerNew;
// Accept data
cout<<" Enter a string to check character array: ";
cin.getline(characterArray, 100);
// Displays data
cout<<" Data entered (character array): "<<characterArray;
}// End of main function
Sample Run:
Enter a string to check pointer using malloc(): this is.
Data entered (using malloc()): this is.
Enter a string to check pointer using new: This is a test.
Data entered (using new): This is a test.
Enter a string to check character array: Check this test.
Data entered (character array): Check this test.
------------------------------------------------------------------------------------------------------------------
2)
#include<iostream>
using namespace std;
// Structure Student definition
typedef struct Student
{
char name[30];
int groupNumber;
float performance[5];
float averageScore;
}Stu;
// Function to accept data for the student
void accept(Stu *ss, int size)
{
// Loops up to the size entered by the user
for(int x = 0; x < size; x++)
{
// Initializes total mark to zero for each student
float total = 0;
// Accepts student data
cout<<" Enter name: ";
cin>>ss[x].name;
cout<<" Enter the group: ";
cin>>ss[x].groupNumber;
cout<<" Enter mark: ";
// Loops 5 times to accept 5 subject mark
for(int y = 0; y < 5; y++)
{
cin>>ss[x].performance[y];
// Calculates total
total += ss[x].performance[y];
}// End of inner for loop
// Calculates average
ss[x].averageScore = total / 3;
// Checks if the counter value is 10 then stop
if(x == 10)
break;
}// End of outer for loop
}// End of function
// Function to display all student information
void display(Stu *ss)
{
// Loops 10 times
for(int x = 0; x < 10; x++)
{
cout<<" Name: "<<ss[x].name;
cout<<" Group: "<<ss[x].groupNumber;
cout<<" Marks: ";
// Loops 5 times to display 5 subject mark
for(int y = 0; y < 5; y++)
cout<<ss[x].performance[y]<<", ";
cout<<" Average: "<<ss[x].averageScore;
}// End of for loop
}// End of function
// Function to display the student information based on average cut off
void displayAvergeStudents(Stu *ss, float avg)
{
// Initially flag is set to zero
int f = 0;
// Loops 10 times
for(int x = 0; x < 10; x++)
{
// Checks if current student average mark is greater than the cut off average mark given as parameter
// Then display student information
if(ss[x].averageScore >= avg)
{
// Set the flag value to one for student found
f = 1;
cout<<" Name: "<<ss[x].name;
cout<<" Group: "<<ss[x].groupNumber;
cout<<" Marks: ";
// Loops 5 times to display 5 subject mark
for(int y = 0; y < 5; y++)
cout<<ss[x].performance[y]<<", ";
cout<<" Average: "<<ss[x].averageScore;
}// End of if condition
}// End of for loop
// Checks if the flag value is zero no such student found
if(f == 0)
cout<<" No student available.";
}// End of function
// Function to sort the student information based on group number
void sortGroupNumber(Stu *ss)
{
int x, y;
// Creates a temporary object
Stu temp;
//Loops till length of the array
for(x = 0; x < 10; x++)
{
//Loops till length of the array minus x minus one times
for(y = 0; y < 3 - x - 1; y++)
{
//Checks if current index position of the array is greater than the next index position of the array
if(ss[y].groupNumber > ss[y + 1].groupNumber)
{
//Swapping process
temp = ss[y];
ss[y] = ss[y + 1];
ss[y + 1] = temp;
}//End of if condition
}//End of inner for loop
}//End of outer for loop
}// End of function
// Main function definition
int main()
{
// To store number of record user wants
int size;
// Accepts size
cout<<" Enter the size: ";
cin>>size;
// Creates an array of objects for Student dynamically as size entered by the user
Stu *ss = new Stu[size];
// Calls function to accept data
accept(ss, size);
cout<<" Display data: ";
// Calls function to display all student information
display(ss);
// Calls the function to sort data
sortGroupNumber(ss);
cout<<" After sorting by group number: ";
// Calls function to display all student information
display(ss);
// Calls function to display student information satisfying the average criteria
cout<<" Display students average more than 4.0: ";
displayAvergeStudents(ss, 4.0f);
}// End of main function
Sample Run:
Enter the size: 20
Enter name: pyari
Enter the group: 1
Enter mark: 10
20
30
40
50
Enter name: mohan
Enter the group: 5
Enter mark: 11
22
33
44
55
Enter name: sahu
Enter the group: 2
Enter mark: 11
12
13
14
22
Enter name: ram
Enter the group: 2
Enter mark: 10
22
11
44
1
Enter name: sym
Enter the group: 1
Enter mark: 10
5
4
11
2
Enter name: rahim
Enter the group: 3
Enter mark: 10
2
45
33
4
Enter name: suresh
Enter the group: 3
Enter mark: 10
22
33
5
6
Enter name: padhy
Enter the group: 4
Enter mark: 11
22
23
4
6
Enter name: panda
Enter the group: 2
Enter mark: 12
23
45
23
2
Enter name: punit
Enter the group: 5
Enter mark: 3
4
6
4
2
Enter name: sarita
Enter the group: 2
Enter mark: 11
22
4
5
6
Display data:
Name: pyari Group: 1
Marks: 10, 20, 30, 40, 50,
Average: 50
Name: mohan Group: 5
Marks: 11, 22, 33, 44, 55,
Average: 55
Name: sahu Group: 2
Marks: 11, 12, 13, 14, 22,
Average: 24
Name: ram Group: 2
Marks: 10, 22, 11, 44, 1,
Average: 29.3333
Name: sym Group: 1
Marks: 10, 5, 4, 11, 2,
Average: 10.6667
Name: rahim Group: 3
Marks: 10, 2, 45, 33, 4,
Average: 31.3333
Name: suresh Group: 3
Marks: 10, 22, 33, 5, 6,
Average: 25.3333
Name: padhy Group: 4
Marks: 11, 22, 23, 4, 6,
Average: 22
Name: panda Group: 2
Marks: 12, 23, 45, 23, 2,
Average: 35
Name: punit Group: 5
Marks: 3, 4, 6, 4, 2,
Average: 6.33333
After sorting by group number:
Name: pyari Group: 1
Marks: 10, 20, 30, 40, 50,
Average: 50
Name: sahu Group: 2
Marks: 11, 12, 13, 14, 22,
Average: 24
Name: mohan Group: 5
Marks: 11, 22, 33, 44, 55,
Average: 55
Name: ram Group: 2
Marks: 10, 22, 11, 44, 1,
Average: 29.3333
Name: sym Group: 1
Marks: 10, 5, 4, 11, 2,
Average: 10.6667
Name: rahim Group: 3
Marks: 10, 2, 45, 33, 4,
Average: 31.3333
Name: suresh Group: 3
Marks: 10, 22, 33, 5, 6,
Average: 25.3333
Name: padhy Group: 4
Marks: 11, 22, 23, 4, 6,
Average: 22
Name: panda Group: 2
Marks: 12, 23, 45, 23, 2,
Average: 35
Name: punit Group: 5
Marks: 3, 4, 6, 4, 2,
Average: 6.33333
Display students average more than 4.0:
Name: pyari
Group: 1
Marks: 10, 20, 30, 40, 50,
Average: 50
Name: sahu
Group: 2
Marks: 11, 12, 13, 14, 22,
Average: 24
Name: mohan
Group: 5
Marks: 11, 22, 33, 44, 55,
Average: 55
Name: ram
Group: 2
Marks: 10, 22, 11, 44, 1,
Average: 29.3333
Name: sym
Group: 1
Marks: 10, 5, 4, 11, 2,
Average: 10.6667
Name: rahim
Group: 3
Marks: 10, 2, 45, 33, 4,
Average: 31.3333
Name: suresh
Group: 3
Marks: 10, 22, 33, 5, 6,
Average: 25.3333
Name: padhy
Group: 4
Marks: 11, 22, 23, 4, 6,
Average: 22
Name: panda
Group: 2
Marks: 12, 23, 45, 23, 2,
Average: 35
Name: punit
Group: 5
Marks: 3, 4, 6, 4, 2,
Average: 6.33333
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.