1. Write C++ code to declare a struct which is designed to hold a name, age and
ID: 3749778 • Letter: 1
Question
1. Write C++ code to declare a struct which is designed to hold a name, age and gpa. 2. Declare a variable called student to be of that struct 3. Declare an array called students where each location of the array is a name, age, and gpa. 4. Print the 5th location of the array 5. Print all the names in the array 6. Which array operations are inefficient and why? arget r S ata next lD 20 So 7. Given the picture of the linked list above, write the struct that will help to define the linked list and write statements to declare the variables: first, target and tail. 8. Write statement(s) to insert a node containing 5 at the front of the list 9. Write statements to insert a node containing 55 at the end of the list 10. Write statements to insert a node containing 25 in in appropriate place in the list 11. Write a statement to delete the node containing 30 from the list.Explanation / Answer
If you post mor than 1 question, as per chegg guilines I have to solve only first question. But I still answered 5. So, please don't dislike the solution.
Ques 1.
struct student1{
// char array to store the name
char name[50];
int age;
float gpa;
};
Ques 2.
// create a variable of type struct student1
struct student1 student;
Ques 3.
// create an array of type struct student1 of size 10
struct student1 students[10];
Ques 4.
// use (.) operator to access attributes of struct
// print name
cout<<"Name : "<<students[4].name<<endl;
// print name
cout<<"Age : "<<students[4].age<<endl;
// print name
cout<<"GPA : "<<students[4].gpa<<endl;
Ques 5.
int i;
// traverse through the array
for( i = 0 ; i < 10 ; i++ )
{
// use (.) operator to access attributes of struct
// print name
cout<<"Name : "<<students[i].name<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.