Question

In: Computer Science

Create a C++ program that makes use of both concepts i.e. Array of structure and array...

Create a C++ program that makes use of both concepts i.e. Array of structure and array within the structure by using the following guidelines:

1. Create an Array of 5 Structures of Student Records

2. Each structure must contain: a. An array of Full Name of Student b. Registration Number in proper Format i.e 18-SE-24 c. An array of Marks of 3 subjects d. Display that information of all students in Ascending order using “Name” e. Search a particular student and update its Marks of any particular subject.

Solutions

Expert Solution

Here we just want to create a program with array of structure and array within structure.

And here search value is the students id number.

#include <cstring>

#include <iostream>

#include <ostream>

using namespace std;

//create the structure

struct student

{

string name;

string id;

int phone_number;

int mark[3];

};

int main(){

struct student stud[5];

int i,search ,choice, subnum;

for(i=0; i<5; i++){ //taking values from user

cout << "\nStudent " << i + 1 << endl;

cout << "Enter roll no" << endl;

cin >> stud[i].id;

cout << "Enter name" << endl;

cin >> stud[i].name;

cout << "Enter phone number" << endl;

cin >> stud[i].phone_number;

for(int j=0;j<3;j++)

{

cout << "Enter Marks " << j+1 << " : ";

cin >> stud[i].mark[j];

}

}

for(i=0;i<5;i++){ //printing values

cout << "\nStudent " << i + 1 << endl;

cout << "Roll no : " << stud[i].id << endl;

cout << "Name : " << stud[i].name << endl;

cout << "Phone no : " << stud[i].phone_number << endl;

for(int j=0;j<3;j++)

{

cout << "mark of sub"<<j+1<<" : "<< endl;

cout << stud[i].mark[j]<<endl;

}

}

//ask for a search value

cout<<"Enter phone number(for searching) "<<endl;

cin>>search;

for(i=0;i<5;i++)

{ //conpare the search value with orginal value

if(stud[i].phone_number==search)

{

cout << "\nResult was" << i + 1 << endl;

cout << "Roll no : " << stud[i].id << endl;

cout << "Name : " << stud[i].name << endl;

cout << "Phone no : " << stud[i].phone_number << endl;

for(int j=0;j<3;j++)

{

cout << "mark of sub"<<j+1<<" : "<< endl;

cout << stud[i].mark[j]<<endl;

}

  

//ask for manipulation

cout<<"do you want to edit the marks?press 1 for yes,2 for no!"<<endl;

cin >>choice;

if(choice ==1){

cout<<"enter the subject number" <<endl;

cin>>subnum;

cout << "Enter new Mark"<< " : ";

cin >> stud[i].mark[subnum-1];

  

}

}}

for(i=0;i<5;i++){ //printing final values

cout << "\nEditted results " << i + 1 << endl;

cout << "Roll no : " << stud[i].id << endl;

cout << "Name : " << stud[i].name << endl;

cout << "Phone no : " << stud[i].phone_number << endl;

for(int j=0;j<3;j++)

{

cout << "mark of sub"<<j+1<<" : "<< endl;

cout << stud[i].mark[j]<<endl;

}

}

return 0;

}

This is the code.. Also including screen shots.

Unfortunately my device didn't accept input more than 2 lines so take only 2 students.

Output :

Please refer this screen shot for actual code incase of any errors.


Related Solutions

Solve in C++ program. Modify the use of queue data structure such that the array used...
Solve in C++ program. Modify the use of queue data structure such that the array used to implement the queue is dynamically allocated for a fast food autoservice
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Directions: Write a C++ program that will create an array of four integers. It will allow...
Directions: Write a C++ program that will create an array of four integers. It will allow the user to enter in four valid scores and store them in the array. ( valid range is 0 - 100) It will compute the letter grade based upon the four scores, namely, A = 90 - 100, B= 80- 89, C = 70-79, D = 60-69, otherwise F. It will display the scores and letter grade to the screen. NOTE: No menu is...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Write a program in c++ to do the following: 2. Create an array to hold up...
Write a program in c++ to do the following: 2. Create an array to hold up to 20 integers. 3. Create a data file or download attached text file (twenty_numbers.txt) that contains UP TO 20 integers. 4. Request the input and output file names from the user. Open the files being sure to check the file state. 5. Request from the user HOW MANY numbers to read from the data file, up to twenty. Request the number until the user...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Program in C: Write a program in C that reorders the elements in an array in...
Program in C: Write a program in C that reorders the elements in an array in ascending order from least to greatest. The array is {1,4,3,2,6,5,9,8,7,10}. You must use a swap function and a main function in the code. (Hint: Use void swap and swap)
Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT