Question

C++ Write a program that determines which of the 6 states had the most traffic tickets...

C++

Write a program that determines which of the 6 states had the most traffic tickets last year. The 6 states are California, Georgia, Alabama, Illinois, Michigan, and Florida. The program should have the following 2 functions, which are called by main.

  1. Int getNumTickets () is passed the name of the state. It asks the user for the number of traffic tickets reported during last year, validates the input and then returns it. It should be called once for each state.
  2. void findHighest () is passed the 6 traffic tickets totals. The function determines which is the highest and prints the name and totals for the state.

Input Validation: Do not accept negative numbers for traffic tickets.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
// function to input the number of tickets
int getNumTickets(string state)
{
// print the message to enter the number of tickets
cout<<"Enter number of traffic tickets for "<<state<<"\n";
int f=1;
int num;
// run an infinite loop until a number > 0 is entered
while(f==1)
{
cin>>num;
if(num>=0)
{
f=0;
}
else
{
cout<<"Invalid input\n Enter again :";
}
}
// return the number
return num;
}
// function to find the highest number of tickets
void findHighest(int tickets[],string six_states[])
{
int m=tickets[0];
int pos=0;
// iterate through the loop and find the highest value and its position
for(int i=0;i<6;i++)
{
if(m<tickets[i])
{
m=tickets[i];
pos=i;
}
}
// print the state with highest number of traffic tickets
cout<<"The number of traffic tickets in "<<six_states[pos]<<" is highest and is equal to "<<m<<"\n";
}
int main()
{
// initialize a string array with the name of the states
string six_states[6]={"California","Georgia","Alabama","Illinois","Michigan","Florida"};
// initialize an int array for the number of tickets
int tickets[6];
// call the getNumTickets function once for each state
for(int i=0;i<6;i++)
{
tickets[i]=getNumTickets(six_states[i]);
}
// call the findHighest function to find the state with highest number of traffic tickets
findHighest(tickets,six_states);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that determines which of the 6 states had the most traffic tickets...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c plus plus determines which of 5 geographic regions within a major city north south east...

    c plus plus determines which of 5 geographic regions within a major city north south east west and central had the fewest reported traffic accidents last year it should have the following function which are called by main int get NumAccidents is passed the name of a region it asks the user for the number of traffic accidents reported in that region during the last year validates the input then returns it. it should be called once for each city...

  • Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast,...

    Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast, Southeast, Northwest, Southwest) had the greatest sales for a quarter. It should include the following two functions which are called only by main. double getSales() - it is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns it. It should be called once for each division. Negative dollar amounts are invalid. void...

  • Help. Write a C++ program that determines which of a company's four divisions (North, South, East,...

    Help. Write a C++ program that determines which of a company's four divisions (North, South, East, West) has the greatest sales for the quarter. It should include three functions at a minimum: float getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, calls a validate() function that will validate the input, and then returns the value back to main(). This function should be called once for each division. void validate() is...

  • Write a C# windows forms program to create a States and Capitals guessing game. A method...

    Write a C# windows forms program to create a States and Capitals guessing game. A method in your program should generate a random number between 1 and 50. Your program should use this number to represent one of the 50 U.S states and then display the name of that state. The user will guess the capital of that state. Another method in your program should get the users answer and check to see whether it is correct. Yet another method...

  • Please Help!(Write a C++ program Only):- The attached file has a number of records giving US...

    Please Help!(Write a C++ program Only):- The attached file has a number of records giving US state names, populations, and number of Federal electors. The fields are delimited by spaces. The first field is a single integer giving the number of states that follow. Guidelines:- 1)Read the first integer and use it to allocate dynamic arrays to contain the state name and the state population. 2) Read in the population data. The electors field is not used. 3) Calculate the...

  • JAVA: File USCapitals.txt is here: Alabama, Montgomery Alaska, Juneau Arizona, Phoenix Arkansas, Little Rock California, Sacramento...

    JAVA: File USCapitals.txt is here: Alabama, Montgomery Alaska, Juneau Arizona, Phoenix Arkansas, Little Rock California, Sacramento Colorado, Denver Connecticut, Hartford Delaware, Dover Florida, Tallahassee Georgia, Atlanta Hawaii, Honolulu Idaho, Boise Illinois, Springfield Indiana, Indianapolis Iowa, Des Moines Kansas, Topeka Kentucky, Frankfort Louisiana, Baton Rouge Maine, Augusta Maryland, Annapolis Massachusettes, Boston Michigan, Lansing Minnesota, Saint Paul Mississippi, Jackson Missouri, Jefferson City Montana, Helena Nebraska, Lincoln Nevada, Carson City New Hampshire, Concord New Jersey, Trenton New York, Albany New Mexico, Santa Fe...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • I am trying to do this assignment: Write a program that reads a list of concepts/strings...

    I am trying to do this assignment: Write a program that reads a list of concepts/strings from the LIST.txt text file (one concept per line), stores them into an array of strings, and then prints the following: 1.Prints a heading “LIST1:” and then prints all the concepts from the array, one concept per line 2.Prints a heading “LIST2:” and then prints all the concepts from the array that do not contain spaces, one concept per line 3.Prints a heading “LIST3:”...

  • Go back to the Statehood sheet. Add a column E called Nicknames. Use a VLOOKUP() function...

    Go back to the Statehood sheet. Add a column E called Nicknames. Use a VLOOKUP() function to add the nicknames from the nicknames sheet into column E of the statehood sheet. Please just give the vlookup function to type in State # nicknames State Delaware Pennsylvania New Jersey Georgia Connecticut Massachusetts Maryland South Carolina New Hampshire Virginia New York North Carolina Rhode Island Vermont Kentucky Tennessee Ohio Louisiana Indiana Mississippi Illinois Alabama Maine Missouri Arkansas Michigan Florida Texas lowa Wisconsin...

  • Go back to the Statehood sheet. Add a column E called Nicknames. Use a VLOOKUP() function to add the nicknames from the...

    Go back to the Statehood sheet. Add a column E called Nicknames. Use a VLOOKUP() function to add the nicknames from the nicknames sheet into column E of the statehood sheet. plz just give me the vlookup function to type in State # nicknames State Delaware Pennsylvania New Jersey Georgia Connecticut Massachusetts Maryland South Carolina New Hampshire Virginia New York North Carolina Rhode Island Vermont Kentucky Tennessee Ohio Louisiana Indiana Mississippi Illinois Alabama Maine Missouri Arkansas Michigan Florida Texas lowa...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT