A researcher intends to analyze data regarding some group of participants in a social event. To help him achieve this, you are required to develop a simple program in C++ that prompts the researcher to key in the number of participants in the event then stores the data that is collected to show expenditures by each participant on food, drinks, transport and entertainment as vote heads. The data should be organized into a 2-D array. There will be two methods for inputting and analyzing the data. The data and the associated operations/methods must be members of a structure. a) Total expenditure for all participants b) Mean expenditure for participants c) The variance for the expenditure among the participants.
Question
A researcher intends to analyze data regarding some group of participants in a social event. To help him achieve this, you are required to develop a simple program in C++ that prompts the researcher to key in the number of participants in the event then stores the data that is collected to show expenditures by each participant on food, drinks, transport and entertainment as vote heads. The data should be organized into a 2-D array. There will be two methods for inputting and analyzing the data. The data and the associated operations/methods must be members of a structure. a) Total expenditure for all participants b) Mean expenditure for participants c) The variance for the expenditure among the participants.
Solution
Sure, here is a simple C++ program that meets the requirements:
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
struct Participant {
vector<double> expenditures;
};
double totalExpenditure(vector<Participant>& participants) {
double total = 0;
for (auto& p : participants) {
for (auto& e : p.expenditures) {
total += e;
}
}
return total;
}
double meanExpenditure(vector<Participant>& participants) {
return totalExpenditure(participants) / participants.size();
}
double varianceExpenditure(vector<Participant>& participants) {
double mean = meanExpenditure(participants);
double temp = 0;
for (auto& p : participants) {
for (auto& e : p.expenditures) {
temp += (mean-e)*(mean-e);
}
}
return temp / participants.size();
}
int main() {
int numParticipants;
cout << "Enter the number of participants: ";
cin >> numParticipants;
vector<Participant> participants(numParticipants);
for (int i = 0; i < numParticipants; ++i) {
cout << "Enter expenditures for participant " << i+1 << " (food, drinks, transport, entertainment): ";
for (int j = 0; j < 4; ++j) {
double expenditure;
cin >> expenditure;
participants[i].expenditures.push_back(expenditure);
}
}
cout << "Total expenditure: " << totalExpenditure(participants) << endl;
cout << "Mean expenditure: " << meanExpenditure(participants) << endl;
cout << "Variance of expenditure: " << varianceExpenditure(participants) << endl;
return 0;
}
This program first defines a Participant structure that contains a vector of expenditures. Then it defines three functions to calculate the total expenditure, mean expenditure, and variance of expenditure. In the main function, it prompts the user to enter the number of participants and their expenditures, and then it calls the three functions to calculate and print the total, mean, and variance of expenditures.
Similar Questions
You are developing a Student Record Management System in C. The system needs to store and manage information for multiple students, including their names, roll numbers, and marks obtained in different subjects. Implement array in structures to read, write, and compute average marks and the students scoring above and below the average marks for a class of N students. INPUT/OUTPUT EXAMPLE: Enter the number of students: 3 Enter details for 3 students: Student 1: Name: A Roll Number: 1 Marks in 5 subjects: Subject 1: 12 Subject 2: 13 Subject 3: 14 Subject 4: 15 Subject 5: 16 Student 2: Name: BB Roll Number: 2 Marks in 5 subjects: Subject 1: 11 Subject 2: 13 Subject 3: 12 Subject 4: 15 Subject 5: 14 Student 3: Name: CC Roll Number: 10 Marks in 5 subjects: Subject 1: 13 Subject 2: 14 Subject 3: 16 Subject 4: 17 Subject 5: 11 Class average marks: 13.73 Students scoring above average: A (Roll Number: 1) CC (Roll Number: 10) Students scoring below average: BB (Roll Number: 2)
The theatre wants to collect the names of all audience who visit the theatre and calculate the total amount collected as fare for the tickets from the audience. Write a Java program
Imagine you are a teacher in a programming class, and you want to create a simple program to manage and analyze the scores of your students. Your task is to develop a C program that performs basic operations on an array representing the students' scores. The program will help you quickly view, analyze, and update the scores. Here's a breakdown of the tasks:1. Initialize Array:o Declare an array named studentScores to store the scores of 5 students in your programming class.o Initialize the array with random scores between 50 and 100 to represent their performance in a recent assignment.2. Display Scores:o Implement a function named displayScores that takes the array of scores and its size as parameters. This function should display the scores of each student, allowing you to easily check the performance distribution in the class.3. Calculate Average:o Implement a function named calculateAverage to calculate and return the average score of the students. This will help you understand the overall performance of the class.4. Find Highest Score:o Implement a function named findMaxScore that finds and returns the highest score in the array. Knowing the highest score will give you an idea of the best-performing student.5. Update Scores:o Implement a function named updateScores to increment each student's score by 5. This simulates a bonus or extra credit being added to the assignment.6. Main Function:o In the main function, initialize the array with scores, display the initial scores, calculate and display the average, find and display the highest score, update the scores, and finally, display the updated scores.
In a theatre four types of audience come to watch movies. They are,1. Singles2. Couples3. A set of parents + 1 kid4. A set of parents + 2 kidThe theatre ticket rate for any audience group as follows: 1st person in the group -Rs.400/- 2nd person in the group -Rs.300/- 3rd person in the group -Rs.200/- 4th person in the group -Rs.100/-The theatre wants to collect the names of all audience who visit the theatre and calculate the total amount collected as fare for the tickets from the audience. Write a Java program that implements the above
In a theatre four types of audience come to watch movies. They are,1. Singles2. Couples3. A set of parents + 1 kid4. A set of parents + 2 kidThe theatre ticket rate for any audience group as follows: 1st person in the group -Rs.400/- 2nd person in the group -Rs.300/- 3rd person in the group -Rs.200/- 4th person in the group -Rs.100/-The theatre wants to collect the names of all audience who visit the theatre and calculate the total amount collected as fare for the tickets from the audience. Write a Java program that implements the above using the concept of Constructor Overloading (Polymorphism).Input 1:Enter the total number of audience group : 2Enter the group category: 1Enter name of first person: KaushikEnter the group category: 3Enter name of first person: AshmiEnter name of second person: KrishEnter name of third person: MahiOutput 1The audience names areKaushikAshmiKrishMahiThe total amount collected: 1300Input 2:Enter the total number of audience group : 3Enter the group category: 1Enter name of first person: KaushikEnter the group category: 3Enter name of first person: AshmiEnter name of second person: KrishEnter name of third person: MahiEnter the group category: 4Enter name of first person: RashmiEnter name of second person: RakeshEnter name of third person: JesiEnter name of fourth person: MehaOutput 2The audience names areKaushikAshmiKrishMahiRashmiRakeshJesiMehaThe total amount collected: 2300
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.