Question

In: Mechanical Engineering

C++ Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go...

C++ Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, the 405 services the 5, and the 290 services the 90.

Your program will prompt the user to type a highway number ("Please enter a highway number, Ex: 65: "), read in the number typed by the user, and print out whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves.

Also your program must indicate if the (primary) highway runs north/south or east/west, that it is an invalid number if not between 0 and 999.

Solutions

Expert Solution

Code for the same is attached below,please do go through it.

int main() {
int highwayNumber;
int primaryNumber;
cout<<"Please enter a highway number: ";
cin >> highwayNumber;

if (highwayNumber >= 1 && highwayNumber <= 999) {
if (highwayNumber <= 99) {
if (highwayNumber % 2 == 0) {
cout << "I-" << highwayNumber << " is primary, going east/west." << endl;
} else {
cout << "I-" << highwayNumber << " is primary, going north/south." << endl;
}
} else {
primaryNumber = highwayNumber;
highwayNumber %= 100;
if (highwayNumber % 2 == 0) {
cout << "I-" << primaryNumber << " is auxiliary, serving I-" << highwayNumber << ", going east/west." << endl;
} else {
cout << "I-" << primaryNumber << " is auxiliary, serving I-" << highwayNumber << ", north/south." << endl;
}
}
} else {
cout << highwayNumber << " is not a valid interstate highway number." << endl;
}
return 0;
}

Input and Output in C++ Complier is attached below.

Please do hit that like button if my answers were of any help to you.

Thank you.


Related Solutions

Write an application named OddNums that displays all the odd numbers from 1 through 99. All...
Write an application named OddNums that displays all the odd numbers from 1 through 99. All ODD numbers should show all together(Should not need to scroll down), do it in 10 rows. FOR C#
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
In the Main method add the code that counts by 1, 2, 3, 4, and 5 – see output below Use a nested for loop to implement the series of numbers C# Syntax:
code in C# How to count by n:   In the Main method add the code that counts by 1, 2, 3, 4, and 5 – see output below Use a nested for loop to implement the series of numbers C# Syntax:  The C# syntax for variable declarations, and if, if-else, while, and for statements is identical to Java   C# console output:  Console.Write("{0,2} ", number); // in this context number is an integer variable writes a number right-aligned in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT