Assistance in a walkthrough of a lab

Lab: You are to develop a program that will determine what time zone random samplings of residents live. The 4 choices of course are Eastern (E), Central (C), Mountain (M), and Pacific (P) Time zones.

The report you produce will show the total number of residents in each time zone, and the associated %age.

You will need to determine the best looping mechanism to handle ANY amount of input.

You design the output report. Make it professional looking and formatted.

Be sure to show %ages with 2 decimals.

Be sure to turn in source code and output. Test your program appropriately. (E.g. what if no one lived in one or more of the time zones).

Lastly, write this program 2 ways – one with CASE and one way with IF/Else flow of control. Tell me which way you prefer, and why?

*Hello, i'm relatively new to Structured Programming C++ and my teacher is throwing us into the deep end with this lab. I only have an understanding of the basics, so i'm not doing well in understanding this lab. I've defined a few things that I think i'll need in my program, but that's it. If you could help, it'd be much appreciated. Thank you.*

#include <iostream>
using namespace std;
int main ()
{
int E; //Eastern Time Zone
int C; //Central Time Zone
int M; //Mountain Time Zone
int P; //Pacific Time Zone
double residents;
double age;
double total_residents; //Total number of residents in each time zone
double percent_age; //Associated percent age
determine what time zone random samplings of residents live. The 4 choices of course are Eastern (E), Central (C), Mountain (M), and Pacific (P) Time zones.

You will need to determine the best looping mechanism to handle ANY amount of input.

What is the actual input? Is just the list of timezones, one per resident?

Would this be a valid input:
EECMP
CPE

That would tally up to:
E 3  37.50%
C 2  25.00%
M 1  12.50%
P 2  25.50%
My professor didn't really specify. What I put above was all the directions we got. I figure what you have is valid, i'm just not quite sure how you would put that in C++ code. :/
Ok, on the assumption that the input is one timezone character per resident:

You have to read characters one by one. For each character, using either CASE or IF ELSE construct increment the count of appropriate counter.

You clearly need four integer-type counters, like the E, C, M, P that you already have, but I would recommend unsigned type and more descriptive names.

What should be the value of counters before any input has been handled?


The total of residents is the sum of the residents of the four zones (and of same type as the zone counts). This can be counted after the input has ended.

You can calculate each percentage directly for printing rather than store in variable.

Calculating a percentage means division and from integral numbers that requires promotion to floating point. Use a cast:
1
2
3
4
unsigned int A;
unsigned int B;
// set A and B
auto ratio = static_cast<double>(A) / B;


Header <iomanip> contains stream manipulators std::setw, std::fixed and std::precision. Use them for "professional" format.
We have to basically do the lab twice, once using CASE and then IF/ELSE. I'm a little bit familiar with IF/ELSE and haven't once used CASE.

I'm not sure what you mean by "unassigned int A and unassigned int B" since we've never gone over them.

I'm more than happy with using whatever is more comfortable for you, i'm just very stuck because as I mentioned my professor lectures for an hour or so, then gives us an assignment not really based off of what he talked about.

I've updated what I have a little bit, not sure if it helps but this is what i've done so far.

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
// Assignment 4: Part 1: U.S. Residency Report

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

int E; //Eastern Time Zone
int C; //Central Time Zone
int M; //Mountain Time Zone
int P; //Pacific Time Zone
double residents;
double age;
double total_residents; //Total number of residents in each time zone
double percent_age; //Associated percent age

cout << "\n\n\n\n\n\n\n\n\n";

cout << right << setw(45) << "Enter a random number of residents: ";
cin >> residents;

Thanks by the way for helping me with this keskiverto, I hope we can knock it out relatively easily. :)
Topic archived. No new replies allowed.