Question

In: Computer Science

2) You've been hired by Superfluous Stats to write a C++ console application that analyzes a...

2) You've been hired by Superfluous Stats to write a C++ console application that analyzes a string. Prompt for and read from the user a string that may contain spaces. Then prompt for and read from the user a single character. Print the following stats about the string and character inputs. Use formatted output manipulators (setw, left/right) to print the following rows about the string:

          ● The string value.

          ● The string length.

          ● The spot, if any, where the character is found within the string.

And the following rows about the character:

          ● The character value.

          ● Whether the character is an alphabetic character.

          ● Whether the character is a numeric character.

          ● Whether the character is a punctuation character.

And columns:

          ● A left-justified label.

          ● A right-justified value.

Define constants for the column widths. The output should look like this:

Welcome to Superfluous Stats

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

Enter a string: Detroit Michigan

Enter a character: r

String s

Value:                  Detroit Michigan

Length:                               16

Index:                                 3

Character c

Value:                                 r

Is alpha?                              2

Is digit?                              0

Is punctuation?                        0

End of Superfluous Stats

Note that you may get a value for true that is not 1. Do not use this sample input for the final run that is pasted below.

Solutions

Expert Solution

Solution:

#include<iostream>

#include<string>

#include<ctype.h>

#include<iomanip>

using namespace std;

int main()

{

    char s[257];

    char c;

    int i;

    cout<<"Welcome to Superfluous Stats\n";

    cout<<"----------------------\n";

    cout<<"Enter a string: ";

    cin.getline(s,256);

    cout<<"Enter a character: ";

    cin>>c;

    int n=string(s).length();

    cout<<"String s\n";

    cout<<"Value:"<<setw(30)<<s<<"\n";

    cout<<"Length:"<<setw(25)<<n<<"\n";

    i=0;

    for(char x:s)

    {   

        if(x==c)

            break;

        i++;

    }

    if(i==n)

        i=-1;

    cout<<"Index:"<<setw(25)<<i<<"\n";

    cout<<"Character c\n";

    cout<<"Value:"<<setw(25)<<c<<"\n";

    cout<<"Is alpha?"<<setw(22)<<isalpha(c)<<"\n";

    cout<<"Is digit?"<<setw(22)<<isdigit(c)<<"\n";

    cout<<"Is punctutation?"<<setw(15)<<ispunct(c)<<"\n";

    cout<<"End of Superfluous Stats";


    return 0;

}

Output:


Related Solutions

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...
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)...
Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and...
Lab 10-2: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...
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...
write a c++ code for following application You have been hired by XYZ Car Rental to...
write a c++ code for following application You have been hired by XYZ Car Rental to develop a software system for their business. Your program will have two unordered lists, one of Cars and one of Reservations. The Car class will have the following data: string plateNumber (this is the key) string make string model enum vehicleType (VehicleType Enumeration of options: sedan, suv, exotic) double pricePerDay bool isAvailable isAvailable should be set to true on initialization, and a public setter...
write a c# console application app that reads all the services in the task manager and...
write a c# console application app that reads all the services in the task manager and automatically saves what was read in a Notepad txt file.  Please make sure that this program runs, also add some comments
Loops Write a simple C/C++ console application that will calculate the equivalent series or parallel resistance....
Loops Write a simple C/C++ console application that will calculate the equivalent series or parallel resistance. Upon execution the program will request ether 1 Series or 2 Parallel then the number of resisters. The program will then request each resistor value. Upon entering the last resistor the program will print out the equivalent resistance. The program will ask if another run is requested otherwise it will exit.
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT