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 programming Explain the difference between the statements on the left and the statements on the...
c programming Explain the difference between the statements on the left and the statements on the right for each group of statements, give the final value of x if the initial value of x is 1 If (x>=0) x =x +1; Else if (x>=1) x = x+2; If ( x>=0) x = x+1; if (x>= 1) x=x+2;
In C programming, Thank you Declare an array that can contain 5 integer numbers. Use a...
In C programming, Thank you Declare an array that can contain 5 integer numbers. Use a for loop to ask the user for numbers and fill up the array using those numbers. Write a program to determine the 2 largest integers in the array, and print those numbers. Hint: You can declare integer variables “largest” and “secondLargest” to keep track as you make comparisons using the if...elseif statement. The following is an example of how your program should look when...
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...
In C++ Declare an integer array of size 20 and assign the array with 20 randomly...
In C++ Declare an integer array of size 20 and assign the array with 20 randomly generated integers in the range [1, 100]. Shuffle the data in the array so that all numbers smaller than 50 are put before the numbers greater or equal to 50. Note you are not allowed to create any other arrays in the program. Finally, print out the shuffled array. (25 points) #include<iostream> using namespace std; const int NUM = 20; int main() {      ...
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...
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...
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...
In C programming Declare two 2d arrays n0[MAX_ROW][MAX_COL], n1 [MAX_ROW][MAX_COL]. Then, loop through the 2d array...
In C programming Declare two 2d arrays n0[MAX_ROW][MAX_COL], n1 [MAX_ROW][MAX_COL]. Then, loop through the 2d array and save the results in n0 and n1: for (i=0; i<MAX_ROW; i++)   for (j=0; j<MAX_COL;j++){        //calculate number of zeros around entry a[i][j]        n0[i][j] =        //calculate number of ones around entry a[i][j]        n1[i][j] =   } Set the MAX_ROW and MAX_COL to a small number and display all three 2d arrays on the screen to verify that the calculations are correct. You may still use command-line...
In C++, cstring is implemented as an array of characters. What is the difference between cstring...
In C++, cstring is implemented as an array of characters. What is the difference between cstring and a regular array of characters? In other words, how do you distinguish them?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT