Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read the file and make a vector with the total for each Gender/Alchohol frequenc

ID: 3937300 • Letter: R

Question

Read the file and make a vector with the total for each Gender/Alchohol frequency. C++

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/Alcohol 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

Explanation / Answer

#include <stdio.h>
#include <string.h>

int main(void) {
int age;
char gender[10];
   int weight;
   int beers;
   int shots;
   int hours;
double a;
  
printf("Should I Drive? ");
   printf("What is your age? ");
   scanf("%d", &age);
   if (age < 21)
   {
       printf("No, you shouldn't drive.");
   }
   else
   {
       printf("Okay. Are you male or female? ");
       scanf("%s", &gender);
if (strcmp(gender, "male") == 0)
{
a = 0.73;
}
if (strcmp(gender, "female") == 0)
{
a = 0.66;
}
       printf("So you are a %s. And how much do you weigh? ", gender);
       scanf("%d", &weight);
       printf("That's enough with the personal questions. How many beers (12 oz.) have you had to drink? ");
       scanf("%d", &beers);
       printf("And how many shots (1.25 oz.)? ");
       scanf("%d", &shots);
  
double content = ((beers * (12 * .05)) + (shots * (1.25 * .4)));
       printf("You have had %.2lf oz. of alcohol tonight. ", content);
       printf("How many hours (round down) has it been since you started drinking? ");
       scanf("%d", &hours);
  
double bac = (content * 5.14 / (weight * a)) - (0.015 * hours);

if (bac <= 0.08)
{
double amtunder = 0.08 - bac;
printf("Your BAC is %.3lf under the legal limit. You are legally able to drive.", amtunder);
}
if (bac > 0.08)
{
double amtover = bac - 0.08;
printf("Your BAC is %.3lf over the legal limit. You are not legally able to drive.", amtover);
}
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote