Question

In: Computer Science

Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in...

Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in Assignment 04.1 to C++ code inside the main() function. Your program should prompt for a single 9-digit routing number without spaces between digits as follows: Enter a 9-digit routing number without any spaces: The program should output one of: Routing number is valid Routing number is invalid A C++ loop and integer array could be used to extract the routing number's 9 digits. However since we have not yet covered C++ loops and arrays in class, you can instead assign the digits to integer variables d0,d1,d2,d3,d4,d5,d6,d7,d8 without any point deduction. Doing the latter should help you to understand looping over an array since you have essentially unrolled the loop. This illustrates two conventions: C++ arrays start with index 0, and the 0thdigit is the rightmost digit. Try your program on the following routing numbers: 111000025 and 789456123 One of them is a valid routing number and one of them isn't. Copy and paste the console output for these two routing numbers to a text editor and save the result in a single file named console.txt. Upload the assignment042.cpp and console.txt files to Canvas.

Solutions

Expert Solution

assignment042.cpp

#include <iostream>
using namespace std;

int main(){

    // integer variables to store all digits of routing number
    int d0, d1, d2, d3, d4, d5, d6, d7, d8;
    // taking input from console by one digit using %1d
    // this makes input of 9 digit routing number with no spaces

    cout << "Enter a 9-digit routing number without any spaces: ";
    scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d", &d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, sizeof(d0)*9 );

    // Below is code to check if a number is valid routing number
    // Number is divided into three parts 
    // Those digits will be multiplied by 3, 7, 1 respectively
    // Then all the products will be added
    // If the result is a multiple of 10 then Routing number is valid
    // Else not a valid routing number

    int value;

    // storing the reult in value variable
    value = (d0 * 3) + (d1 * 7) + (d2 * 1) +
            (d3 * 3) + (d4 * 7) + (d5 * 1) +
            (d6 * 3) + (d7 * 7) + (d8 * 1);

    // 10 multiple check to verify a valid routing number
    // Divisible by 10 if reminder is zero
    if (value % 10 == 0){
        cout << "Routing number is valid";
    }
    else {
        cout << "Routing number is invalid";
    }
}


console.txt

Enter a 9-digit routing number without any spaces: 111000025                                                                          
Routing number is valid


Enter a 9-digit routing number without any spaces: 789456123                                                                          
Routing number is invalid 

Have a nice day!


Related Solutions

Create a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function...
Create a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
ceate a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function...
ceate a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project is a web projectb. Make sure it is using C#2. Add a new folder and name it Grades_Logic3. Inside this new folder create a new web form called “Grades”4. Add a label to hold text “Enter Grade”5. Add a text field in front of the label to receive the grade6. Add another label in a new line to display the text “Participation”7. Place a drop-down...
1. Make a Console App (.NET Core) in Visual Studio and name it as A1YourFirstnameLastname. 2....
1. Make a Console App (.NET Core) in Visual Studio and name it as A1YourFirstnameLastname. 2. Implement a vehicle rental management system which is capable of doing the following: • View all, available and reserved vehicles. • Reserve vehicle or cancel a reservation. 3. The application must be menu-based app: 1 - View all vehicles 2 - View available vehicles 3 - View reserved vehicles 4 - Reserve a vehicle 5 - Cancel reservation 6 - Exit 4. NOTE: At...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for name, one for hours worked,and the last for hourly rate. The arrays will receive the information from inputs from the screen.For example, you will ask the following three questions: a) Employee name: b) Hours worked: c) Hourly rate: After you have received all ten records and have inserted them into the array, you will then calculate the hourly rate times the hours worked to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT