 # C++ Problems

Subject Computer Science C-Family Programming

## Question

Problem 1:
For the subway system in C++ City, USA has three fee classifications: student (17 years or less), adult, and senior (65 years old or more). Write a program that counts how many of each fee classification rode the subway on a given day. Assume that the subway conductor has a laptop PC that runs your program. The conductor enters the age of each customer as the subway is under way. Your user instructions tell the conductor to enter a sentinel value of -1 at the end of the day to terminate the entry process for that day. After the sentinel value is entered, the program must display the number of customers in each fee category.

Problem 2:
Write a program that will obtain any two integers between 2 and 10 from the user and display a multiplication table. For example, if the user enters the values 4 and 5, the table would be:

1     2    3    4    5
2     4    6    8    10
3     6    9    12   15
4    8    12   16   20

If the user enters the values 3 and 2, the table would be:

1 2
2 4
3 6

Problem 3:
Please write a program that asks users to input up to 20 positive integers, and then save them into an array. Finds the maximum, minimum and average of the numbers that were entered. You can use -1 to terminate your input.
To find the smallest element in an array, you only need to find the index of the smallest number. You can use the following function to do this.
int index_of_smallest(const int a[], int start_index, int used_size) {
int min = a[start_index], index_of_min = start_index;
for(int i = start_index+1; i < used_size; i++){
if(a[i] < min) {
min = a[i]; index_of_min = i;
}
} return index_of_min;
}

Note that you can write two more functions:
1) One similar to the one that finds the index of smallest number for finding the index of the largest number; and
2) one that computes the average and returns it to the main.

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

// Subway.cpp : Defines the entry point for the console application.
//
//This program is to count the number of patrons in the subway. First, a patron's age
// is entered. Next, the number of various customers is calculted. Finally, the counts
//    are displayed.

#include "stdafx.h"
#include <iostream>

using namespace std;
//Beginning of Main Function
int _tmain(int argc, _TCHAR* argv[])
{
//
int age=0,cCnt=0,aCnt=0,sCnt=0;

//Enter age until the sential value being -1 to stop the loop
while(!(age==-1))
{

cout << "\nPlease enter customer's age: " << endl;
cin >> age;

//Count according to age
if (age<=17)
{
++cCnt;
}
else if(age>=18 && age<=64)
{
++aCnt;
}
else if(age>=65)
{
++sCnt;
}

}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

## Related Homework Solutions

Parsing Line Input in C++ \$28.00
Programming
Computer Science
C++
Classes
ASCII Files
Individual Words
Arrays
Reverse Order
OOP
Functions
Algorithms
Parsing Lines
Strings
Loops
Output
Memory Leaks
One Line Object
Functions in Programming Language C \$5.00
Programming
Computer Science
Arrays
Arguments
Integers
Elements
Variables
Statements
Distances
Absolute Values
Indexes
Input
Output
Programming Questions \$20.00
Programming
C++
Computer Science
Integers
Series
Savings Accounts
Balance
Loops
Statements
Variables
Interest Rates
Deposits
Withdrawals
Input
Output
Programming Questions \$40.00
Programming
C++
Computer Science
Strings
Codes
Characters
Pointers
Buffer
CMYK Colors
Encoding
Issues
Compiler Errors
Assembly Language
Intel Machine
Lines
Symbols
Shapes Program in C++ \$30.00
Programming
C++
Shapes
Codes
Metric Conversions
Mathematics
Functions
Area
Centimeters
Kilos
Points
Celsius
Fahrenheit
Circle
Square
Rectangle
Display Choices