Question

In: Computer Science

Explain the difference between array and structure based on their usage in C++ programming. Declare a...

  1. Explain the difference between array and structure based on their usage in C++ programming.
  1. Declare a structure called studentScore which contains name of student, registration number of students, course code and marks.
  1. Declare structure variable named studentCS680 based on the structure in (b) to store fifty (50) students’ data.
  1. Write a program that prompts a user to enter data for 50 students in a structure variable declared in (b) and calculate the average mark.

Solutions

Expert Solution

a) an array is a contiguos block of memory which is allocated during compile time to store data belonging to a particular datatype.Whereas the structure is defined as a template which can used to encapsulate related data into one object.

for example int a[10]; //this is an array

whereas struct student

{

string name;

string rollId;

}

this is a structure of student which acts as a template.

b)

struct StudentScore

{

string name;

string regNo;

string courseCode;

float marks;

};

c)StudentScore studentCS680[50];

d)

void input(){

cout<<"Enter data for 50 students";

float avg = 0.0;

for(int i = 0;i < 50;++i)

{

cout<<"\nName : ";

getline(cin,studentCS680[i].name);

cout<<"\nReg No: ";

getline(cin,studentCS680[i].regNo);

cout<<"\nCourseCode : ";

getline(cin,studentCS680[i].courseCode);

cout<<"\nMarks : ";

cin >> studentCS680[i].marks;

avg += studentCS680[i].marks;

}

avg = avg / 50;

cout<<"\nAverage "<<avg;

}


Related Solutions

C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department...
C++ Programming Enum - Structure - Array You are asked to develop software for HR department to calculate employee’s weekly salary. The program should contain the following information about a student by declaring a struct: Name (string of characters)        Employee ID (string of characters)        Level (ENGINEER, MANGER, DIRECTOR)        Hourly Rate (floating-point number)        Working Hours (floating-point number)        Weekly Salary (floating-point number) Your program will read an employee data and print the information of employee’s Name, Employee...
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
C++ Programming Simply explain what the difference between "including" a header file and using a compiled...
C++ Programming Simply explain what the difference between "including" a header file and using a compiled library file during linking? Where are the C++ header files and compiled C++ library files on your computer?
C++ Implement the array based Binary Heap data structure as discussed in class. This structure should...
C++ Implement the array based Binary Heap data structure as discussed in class. This structure should have a couple of constructures (default constructor, and a constructor that takes an array pointer and a size), a method for inserting items into the heap, a method for removing items from the heap, and a method that returns the number of items currently stored in the heap. This implementation should be templated so that it can store any type of data (you may...
Difference between array and list? Explain in your own words.
Difference between array and list? Explain in your own words.
What is an array-based list? What is a resizable list? What is the difference between a...
What is an array-based list? What is a resizable list? What is the difference between a list’s capacity and its size? When a list is expanded, is the size changed or is its capacity changed?
C programming What is an array? Explain by taking an example that how can we take...
C programming What is an array? Explain by taking an example that how can we take input and output in 1D array?
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
Description CSCI 1151, Fall 2019 Programming Assignment 5 – Structure Construct an array of a structure...
Description CSCI 1151, Fall 2019 Programming Assignment 5 – Structure Construct an array of a structure to store the information of vehicles. This structure should consist of: an integer for the vehicle identification number (ID); an integer for the mile driven; an integer for the number of gallons used by the vehicle; and a string for the vehicle’s manufacture. Write a C program that get (input) the information of the vehicles from a file, cardb.txt, one structure per vehicle. Your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT