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 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 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])...
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++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt the user for 6 integer values and store them in arr. Prompt the user for a target integer target. Search for targetin arr. If targetis found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names intArray17.b. Create a loop to calculate the sum of every element in the first column.c. Create a loop to calculate the sum of every element in the array.
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names...
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names intArray17. Create a loop to calculate the sum of every element in the first column. Create a loop to calculate the sum of every element in the array.
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
The purpose of this C++ programming assignment is to practice using an array. This problem is...
The purpose of this C++ programming assignment is to practice using an array. This problem is selected from the online contest problem archive, which is used mostly by college students worldwide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest. For your convenience, I copied the description of the problem below with my note on the I/O and a sample executable. Background The world-known gangster Vito Deadstone...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT