Question

In: Computer Science

You've been hired by Avuncular Addresses to write a C++ console application that analyzes and checks...

You've been hired by Avuncular Addresses to write a C++ console application that analyzes and checks a postal address. Prompt for and get from the user an address. Use function getline so that the address can contain spaces. Loop through the address and count the following types of characters:

        ● Digits (0-9)

        ● Alphabetic (A-Z, a-z)

        ● Other

Use function length to control the loop. Use functions isdigit and isalpha to determine the character types. Use formatted output manipulators (setw, left/right) to print the following rows:

        ● Address

        ● String length

        ● Number of digits

        ● Number of alphas

        ● Number of other characters

And two columns:

        ● A left-justified label.

        ● A right-justified value.

Then test the number of digits and number of alphas. If digits is less than two or alphas is less than three, print an invalid address message. Otherwise, print a valid address message. Define constants for the minimum number of digits and alphas, and the column widths. The output should look like this for invalid and valid input:

Welcome to Avuncular Addresses

------------------------------

Enter an address: 1 West Liberty St

Address:     1 West Liberty St

Length:                     16

Digits:                      1

Alphas:                     12

Other:                       3

Address is invalid!

End of Avuncular Addresses

Welcome to Avuncular Addresses

------------------------------

Enter an address: 110 Main St

Address:           110 Main St

Length:                     11

Digits:                      3

Alphas:                      6

Other:                       2

Address is valid!

End of Avuncular Addresses

Solutions

Expert Solution

Code:

#include<iostream>
#include<cstring>
#include<iomanip>

using namespace std;
int main()
{
   string address;
   int num=0,i,alpha=0,other=0;/*Declaring variables*/
   cout<<"Welcome to Avuncular Addresses"<<endl;
   cout<<"------------------------------"<<endl;
   cout<<"Enter an address:";
   getline(cin,address);/*Reading input from the user*/
   cout<<"Address:"<<setw(15)<<address<<endl;/*Printing the address*/
   cout<<"Length: \t"<<address.length()<<endl;/*Length of the address*/
   for(i=0;i<address.length();i++)
   {
       if(isdigit(address[i]))
       {/*If digit increse the coutn of num*/
           num++;
       }
       else if(isalpha(address[i]))
       {/*If alphabet increase the cout of alpha*/
           alpha++;
       }
       else
       {/*Else increase other*/
           other++;
       }
   }
   cout<<"Digits: \t"<<num<<endl;
   cout<<"Alphas: \t"<<alpha<<endl;
   cout<<"Others: \t"<<other<<endl;   /*Printing the digits alphabets and others*/
   if(num<2 || alpha<3)
   {/*If digit is less than 2 or alpha is less than 3*/
       cout<<"Address is invalid!"<<endl;
   }
   else
   {/*else*/
       cout<<"Address is valid!"<<endl;
   }
   cout<<"End of Avuncular Addresses"<<endl;
}

Output:

Indentation:


Related Solutions

You've been hired by Water Wonders to write a C++ console application that analyzes lake level...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. MichiganHuronLakeLevels.txt. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder \). The input file may be placed in any folder but a path must be specified to locate it. MichiganHuronLakeLevels.txt Down below: Lake Michigan and Lake Huron - Average lake levels - 1860-2015 Year    Average level (meters) 1860    177.3351667 1861    177.3318333 1862    177.316...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder <project-name>\<project-name>). The input file may be placed in any folder but a path must be specified to locate it. The input file has 158 lines and looks like this: Lake Michigan and Lake Huron - Average lake levels - 1860-2015 Year    Average level (meters)...
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays...
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:         ● Subtotal using a cost of $3.50 per yogurt.         ● Subtotal...
C# I need working code please Write a console application that accepts the following JSON as...
C# I need working code please Write a console application that accepts the following JSON as input: {"menu": { "header": "SVG Viewer", "items": [ {"id": "Open"}, {"id": "OpenNew", "label": "Open New"}, null, {"id": "ZoomIn", "label": "Zoom In"}, {"id": "ZoomOut", "label": "Zoom Out"}, {"id": "OriginalView", "label": "Original View"}, null, {"id": "Quality"}, {"id": "Pause"}, {"id": "Mute"}, null, {"id": "Find", "label": "Find..."}, {"id": "FindAgain", "label": "Find Again"}, {"id": "Copy"}, {"id": "CopyAgain", "label": "Copy Again"}, {"id": "CopySVG", "label": "Copy SVG"}, {"id": "ViewSVG", "label": "View...
Write a C++ console application to simulate a guessing game. Generate a random integer between one...
Write a C++ console application to simulate a guessing game. Generate a random integer between one and 100 inclusive. Ask the user to guess the number. If the user’s number is lower than the random number, let the user know. If the number is higher, indicate that to the user. Prompt the user to enter another number. The game will continue until the user can find out what the random number is. Once the number is guessed correctly, display a...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Write a Java console application that reads a string for a date in the U.S. format...
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY  For example, if the input is 02/08/2017, your program should output 08.02.2017
Write a console application to total a set of numbers indicated and provided by a user,...
Write a console application to total a set of numbers indicated and provided by a user, using a while loop or a do…while loop according to the user’s menu choice as follows: C++programming Menu 1. To total numbers using a while loop 2. To total numbers using a do...while loop Enter your menu choice: 1 How many numbers do you want to add: 2 Enter a value for number 1: 4 Enter a value for number 2: 5 The total...
Applications : The Logit Model ) Suppose that you've been hired to work as an analyst...
Applications : The Logit Model ) Suppose that you've been hired to work as an analyst at a credit card department of a major bank. Your job is to analyse the historical card sales data, and to make recommendations to the management team. Suppose that in the past, your bank has been offering a choice of five credit cards, each with different level of annual interest and fees. Using the historical sales data, you estimated the following Logit model (using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT