Answer to Question #11911 in C++ for azreen

Question #11911
International Book Fair which was held for 30 days attracted many visitors. Only those visitors
with passes were allowed to enter. Number of passes issued for each day was recorded. You
need to analyze the success of the book fair based on the following:
(a) calculates the total visitors who went to the book fair.
(b) calculates the average number of visitors.
(c) calculates the number of days which has the number of visitors more than 50.
1
Expert's answer
2012-07-17T11:33:01-0400
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <iomanip>
using namespace std;

int main() {
int *visitors;
visitors = new int[30];
srand((unsigned) time(NULL));
for (int i = 0; i < 30; i++) {
& visitors[i] = rand() % 100;
}
cout << "--------------------" << endl;
cout << setw(6) << "Day" << setw(10) << "Visitors" << endl;
cout << "--------------------" << endl;
for (int i = 0; i < 30; i++) {
& cout << setw(6) << i + 1 << setw(10) << visitors[i] << endl;
}
cout << "--------------------" << endl;
int total = 0;
double average = 0;
int number = 0;
for (int i = 0; i < 30; i++) {
& total += visitors[i];
& if (visitors[i] > 50)
& number++;
}
average = total / 30;
cout.setf(ios::fixed);
cout.precision(2);

cout << endl;
cout << "(a) Total visitors who went to the book fair: quot; << total
& lt;< endl;
cout << "(b) Average number of visitors: quot; << average
& lt;< endl;
cout << "(c) Number of days which has more than 50 visitors: quot; << number
& lt;< endl;

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS