ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 09 May 2017 My Price 11.00

Analyze Data in C++

Analyze Data in C++

We will analyze data collected about student alcohol use.

A simplifed text file with alcohol usage data is attached to this lab. It is based on http://archive.ics.uci.edu/ml/datasets/STUDENT+ALCOHOL+CONSUMPTION. The data has been restricted to only show the student's gender, age, and weekend alcohol use.

Big Picture:

  • Ask the user for an age range (min and max)
  • Search the file to collect the information the user asked for
  • Display the data as a bar chart

Details

You want to read the file and make a vector with the total for each Gender/Alchohol frequency. The vector will have 10 spaces, they are numbered 0-9. We need to encode the gender and frequency into these spaces. The gender can be either M or F. The frequency can be 1 (very low) to 5 (very high). To fit these in the numbers 0-9, we can store M values in even spaces and F values in odd spaces.

  • If M then store in position: frequency*2-2
  • If F then store in position: frequency*2-1

Remember to take into account that the user only cares about certain ages.

In each position of the vector, count how many people met the requirement. If 7 males said they drank with frequency 1, then the position 0 in the vector should store 7. (1*2-2=0)

To make the data easy to visualize, draw it as a bar chart. Draw an X for a count of 10 and show the remainder as an integer.

Here are some function prototypes that may help you. You are not required to use them, they are only a suggestion.

//Searchs the file given and fill in a vector with the number
//of people who drink at each level 1-5, for both males and females
//Only count people with min_age <= age <= max_age
void analyze(string filename, vector<int> & results, int min_age, int max_age);
//Prints out the vector as a bar chart
void print_chart(vector<int> & results);
//Print a single row X for a 10, int 1-9 for remainder
//Example: Prints 27 as XX7 and 31 as XXX1
void print_bar(int num);

Example Run

Analyze Alcohol Data
Enter Minimum Age as integer: 0
Enter Max Age as integer: 100
M Freq. 1 XXXXX7
F Freq. 1 XXXXXXXXX4
M Freq. 2 XXX4
F Freq. 2 XXXXX1
M Freq. 3 XXX5
F Freq. 3 XXXX6
M Freq. 4 XXX7
F Freq. 4 X4
M Freq. 5 XX4
F Freq. 5 4
Create new Table? (y/n)y
Enter Minimum Age as integer: 16
Enter Max Age as integer: 16
M Freq. 1 X8
F Freq. 1 XX4
M Freq. 2 9
F Freq. 2 X4
M Freq. 3 7
F Freq. 3 8
M Freq. 4 X
F Freq. 4 6
M Freq. 5 6
F Freq. 5 2
Create new Table? (y/n)n

 

F 18 1F 17 1F 15 3F 15 1F 16 2M 16 2M 16 1F 17 1M 15 1M 15 1F 15 2F 15 1M 15 3M 15 2M 15 1F 16 2F 16 2F 16 1M 17 4M 16 3M 15 1M 15 1M 16 3M 16 4F 15 1F 16 3M 15 2M 15 4M 16 1M 16 5M 15 4M 15 1M 15 1M 15 1M 16 1F 15 1M 15 1M 16 1F 15 1F 15 1F 16 2M 15 4M 15 1M 15 1F 16 2F 15 1F 16 4M 16 1M 15 2F 15 1F 16 3F 15 1M 15 4F 15 3F 15 4F 16 1F 15 1M 15 1M 15 1F 16 1F 16 3F 16 5F 16 1F 16 4

Attachments:

Answers

(11)
Status NEW Posted 09 May 2017 02:05 AM My Price 11.00

-----------

Not Rated(0)