Question

In: Computer Science

A certain advertising company has commissioned a study to determine if a recent advertising campaign is...

A certain advertising company has commissioned a study to determine if a recent advertising campaign is effective for certain age groups. Researchers have created a data file (results.txt) which contains the results attained by the study. The first column is the subject’s name (you may assume there is no whitespace in any name) and the second column indicates if the subject has seen the advertisement in question (Y or y means yes, N or n means no). The third column specifies the subject's age and the last column (the 'score') specifies how favorably the subject views the product being advertised (from 0 to 100 with a score of 100 being most favorable). A example of the file results.txt is attached. You should download this file to a convenient place on your hard drive. Please note that the file is a sample only. Your program should work on any data file that is formatted in a similar way.

results.txt example file -

Bailey           Y 16 68
Harrison         N 17 71
Grant            Y 20 75
Peterson         N 21 69
Hsu              Y 20 79
Bowles           Y 15 75
Anderson         N 33 64
Nguyen           N 16 68
Sharp            N 14 75
Jones            Y 29 75
McMillan         N 19 80
Gabriel          N 20 62
Huang            Y 62 21
Willoughby       Y 58 29
Davis            N 33 65
McGregor         Y 41 55

Your assignment is to prompt the user to enter the full pathname to the data file on disk. If the file does not exist in the specified location, your program should exit with a suitable error message.

The first thing your program should do is output to the screen a copy of the data read in from the disk file. This is known as “echoing” the input data. Your program should then calculate and display the the following results:

 Average score for subjects under 18 who have not seen the ad.

 Average score for subjects under 18 who have seen the ad.

 Average score for subjects 18 to 35 (inclusive) who have not seen the ad.

 Average score for subjects 18 to 35 (inclusive) who have seen the ad.

 Average score for subjects over 35 who have not seen the ad.

 Average score for subjects over 35 who have seen the ad.

Display your results to two places of decimals, and write your program to automatically list your six calculated averages one to a line, in the order above, along with a suitable label for each result.

Finally, your program should calculate and display to two places of decimals the overall average score for all of the subjects surveyed. (Note: Mathematically, this is NOT the average of the six averages you calculated previously).

Warning: There may be no subjects in any given category (such as over 35s who have not seen the ad). If so you cannot calculate the average (because you would get a divide by zero error) so instead of the average for that category you should display “No data to report”.

Solutions

Expert Solution

Program:

// C++ program to read data from file and calculate and display the average scores
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
string filePath, name;
char adStatus;
int age, score;
ifstream fin;

// initialize the variables to store the total score for various categories to 0
int scoreU18_N = 0, scoreU18_Y = 0, score18_35_N = 0, score18_35_Y = 0, scoreA_35_N = 0, scoreA_35_Y = 0;
// initialize the variables to store the total number of records for various categories to 0
int n_U18_N = 0, n_U18_Y = 0, n_18_35_N = 0, n_18_35_Y = 0, n_A_35_N = 0, n_A_35_Y = 0;

// input the path to file
cout<<"Enter the path to the file: ";
getline(cin, filePath);
fin.open(filePath); // open the file in read mode

// check that file opened successfully
if(fin.is_open())
{
// read till the end of file
while(!fin.eof())
{
// read a record from file
fin>>name>>adStatus>>age>>score;
// display the read data to console
cout<<left<<setw(30)<<name<<left<<setw(10)<<adStatus<<right<<setw(10)<<age<<right<<setw(10)<<score<<endl;
// add the score and increment the count based on the adStatus and age
// ad seen
if(adStatus == 'y' || adStatus == 'Y')
{
// age < 18
if(age < 18)
{
scoreU18_Y += score;
n_U18_Y++;
}
else if(age <= 35) // 18<= age <= 35
{
score18_35_Y += score;
n_18_35_Y++;
}
else // age > 35
{
scoreA_35_Y += score;
n_A_35_Y++;
}
}
else // ad not seen
{
if(age < 18) // age < 18
{
scoreU18_N += score;
n_U18_N++;
}
else if(age <= 35) // 18 <= age <= 35
{
score18_35_N += score;
n_18_35_N++;
}
else // age > 35
{
scoreA_35_N += score;
n_A_35_N++;
}
}
}

fin.close(); // close the file

cout<<fixed<<setprecision(2);

// calculate and display the average of different categories
cout<<"Average score for subjects under 18 who have not seen the ad: ";
if(n_U18_N == 0)
cout<<"No data to report"<<endl;
else
cout<<(((double)scoreU18_N)/n_U18_N)<<endl;

cout<<"Average score for subjects under 18 who have seen the ad: ";
if(n_U18_Y == 0)
cout<<"No data to report"<<endl;
else
cout<<(((double)scoreU18_Y)/n_U18_Y)<<endl;

cout<<"Average score for subjects 18 to 35 (inclusive) who have not seen the ad: ";
if(n_18_35_N == 0)
cout<<"No data to report"<<endl;
else
cout<<(((double)score18_35_N)/n_18_35_N)<<endl;

cout<<"Average score for subjects 18 to 35 (inclusive) who have seen the ad: ";
if(n_18_35_Y == 0)
cout<<"No data to report"<<endl;
else
cout<<(((double)score18_35_Y)/n_18_35_Y)<<endl;

cout<<"Average score for subjects over 35 (inclusive) who have not seen the ad: ";
if(n_A_35_N == 0)
cout<<"No data to report"<<endl;
else
cout<<(((double)scoreA_35_N)/n_A_35_N)<<endl;

cout<<"Average score for subjects over 35 (inclusive) who have seen the ad: ";
if(n_A_35_Y == 0)
cout<<"No data to report"<<endl;
else
cout<<(((double)scoreA_35_Y)/n_A_35_Y)<<endl;

// calculate and display the overall average score
cout<<"Overall average score: "<<
((double)(score18_35_N + score18_35_Y + scoreA_35_N + scoreA_35_Y + scoreU18_N + scoreU18_Y))/(n_U18_N + n_U18_Y + n_18_35_N + n_18_35_Y + n_A_35_N + n_A_35_Y)<<endl;

}
else // file open failed
cout<<"Unable to open file : "<<filePath<<endl;


return 0;
}

//end of program

Output:

Input file : results.txt

Output:


Related Solutions

Identify the advertising campaign parameters in the Incredible India Campaign? 4. How was the recent Incredible...
Identify the advertising campaign parameters in the Incredible India Campaign? 4. How was the recent Incredible India Campaign different from the previous one? 5. Identify the components of the creative brief for the incredible india 2.0
A manufacturer of pens has hired an advertising agency to develop an advertising campaign for the...
A manufacturer of pens has hired an advertising agency to develop an advertising campaign for the upcoming holiday season. To prepare for this project, the research director decides to initiate a study of the effect of advertising on product perception. Advertisement A greatly undersells the pen’s characteristics. Advertisement B slightly undersells the pen’s characteristics. Advertisement C slightly oversells the pen’s characteristics. Advertisement D greatly oversells the pen’s characteristics. A sample of 24 adult respondents, taken from a larger focus group,...
A manufacturer of pens has hired an advertising agency to develop an advertising campaign for the...
A manufacturer of pens has hired an advertising agency to develop an advertising campaign for the upcoming holiday season. To prepare for this project, the research director decides to initiate a study of the effect of advertising on product perception. Advertisement A greatly undersells the pen’s characteristics. Advertisement B slightly undersells the pen’s characteristics. Advertisement C slightly oversells the pen’s characteristics. Advertisement D greatly oversells the pen’s characteristics. A sample of 24 adult respondents, taken from a larger focus group,...
A manufacturer of pens has hired an advertising agency to develop an advertising campaign for the...
A manufacturer of pens has hired an advertising agency to develop an advertising campaign for the upcoming holiday season. To prepare for this project, the research director decides to initiate a study of the effect of advertising on product perception. An experiment is designed to compare five different advertisements. Advertisement A greatly undersells the pen’s characteristics. Advertisement B slightly undersells the pen’s characteristics. Advertisement C slightly oversells the pen’s characteristics. Advertisement D greatly oversells the pen’s characteristics. Advertisement E attempts...
A retail company has started a new advertising campaign in order to increase sales. In the...
A retail company has started a new advertising campaign in order to increase sales. In the past, the mean spending in both the 18–35 and 35+ age groups was at most $70.00. a. Formulate a hypothesis test to determine if the mean spending has statistically increased to more than $70.00. b. After the new advertising campaign was launched, a marketing study found that the sample mean spending for 400 respondents in the 18–35 age group was $73.65, with a sample...
A retail company has started a new advertising campaign in order to increase sales. In the...
A retail company has started a new advertising campaign in order to increase sales. In the past, the mean spending in both the 18–35 and 35+ age groups was at most $70.00 a. Formulate a hypothesis test to determine if the mean spending has statistically increased to more than $70.00. b. After the new advertising campaign was launched, a marketing study found that the sample mean spending for 400 respondents in the 18–35 age group was $73.65, with a sample...
A retail company has started a new advertising campaign in order to increase sales. In the...
A retail company has started a new advertising campaign in order to increase sales. In the past, the mean spending in both the 18–35 and 35+ age groups was at most $70.00. a. Formulate a hypothesis test to determine if the mean spending has statistically increased to more than $70.00. b. After the new advertising campaign was launched, a marketing study found that the sample mean spending for 400 respondents in the 18–35 age group was $73.65, with a sample...
A retail company has started a new advertising campaign in order to increase sales. In the...
A retail company has started a new advertising campaign in order to increase sales. In the past, the mean spending in both the 18–35 and 35+ age groups was at most $70.00. a. Formulate a hypothesis test to determine if the mean spending has statistically increased to more than $70.00. b. After the new advertising campaign was launched, a marketing study found that the sample mean spending for 400 respondents in the 18–35 age group was $73.65, with a sample...
Q4. To determine the effectiveness of the advertising campaign for a new digital video recorder, management...
Q4. To determine the effectiveness of the advertising campaign for a new digital video recorder, management would like to know what proportion of the households is aware of the brand. The advertising agency thinks that this figure is close to .55. The management would like to have a margin of error of ±.025 at the 99% confidence level. a) What sample size should be used? b) A sample of the size calculated in a) has been taken. The management found...
A leading FMCG company has hired an advertising agency to work on its media campaign project....
A leading FMCG company has hired an advertising agency to work on its media campaign project. The project is about to launch a series of dairy products in the country. The total duration of the project is 6 months. The initial amount approved by the sponsors was PKR 11,000,000/- for the entire project. At the end of 4th month, the project is only 35% completed while the Project team had already utilized PKR 7,000,000/- against several expenses. [02 marks] Find...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT