Question

In: Computer Science

Write C++ statements that will align the following three lines as printed in two 20 character...

Write C++ statements that will align the following three lines as printed in two 20 character columns.

Item                                                    Price

Banana Split                                                   8.90

Ice Cream Cake                                            12.99

Solutions

Expert Solution

Item                                                    Price

Banana Split                                                   8.90

Ice Cream Cake                                            12.99

C++ statements that will align the above three lines as printed in two 20 character columns:

#include <iostream>

using namespace std;

int main()
{
    //character array initialization with the given values
    char lines[3][2][20] = {{"Item", "Price"}, 
                            {"Banana Split", "8.90"}, 
                            {"Ice Cream Cake", "12.99"}};
    
    //printing the lines in the required fashion
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 2; ++j) {
            for(int k = 0;k < 20;k++)
            {
                //storing value of the character to the input value,if the value is null then storing space
                char p = lines[i][j][k] == '\0' ? ' ' : lines[i][j][k];
                cout << p;   
            }
        }
        cout << endl;
    }
    return 0;
}

CODE SCREENSHOT:

OUTPUT SCREENSHOT:


Related Solutions

Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
            For Sonya, the following income statements are shown for its two product lines and the...
            For Sonya, the following income statements are shown for its two product lines and the company as a whole: Fruits Vegetables            Total Sales $500,000 $300,000 $800,000 Less: Variable expenses 300,000 270,000 550,000 Contribution margin 200,000 30,000 250,000 Less: Fixed expenses 170,000 80,000 270,000 Operating income $30,000 ($50,000) ($20,000) Even if the Vegetable product line is dropped, some employees have to be kept anyway. Therefore, 10% of the Vegetables line’s fixed expenses will continue. If the Vegetables product line...
3) Which of the following statements is true or false a) Character displacement occurs when two...
3) Which of the following statements is true or false a) Character displacement occurs when two species using the same resource overlap in their distributions and become more similar to each other than they are where they don’t overlap. b) If you wanted to know if an organism which expresses a dominant phenotype is homozygous or heterozygous for a trait (e.g., round pea shape, R_), you could do a “test cross” between the unknown individual (R_) and an individual which...
In C++, The following program reads one character from the keyboard and will display the character...
In C++, The following program reads one character from the keyboard and will display the character in uppercase if it is lowercase and does the opposite when the character is in uppercase. If the character is a digit, it displays a message with the digit. Modify the program below such that if one of the whitespaces is entered, it displays a message and tells what the character was. // This program reads one character from the keyboard and will //...
How do I write a C# and a C++ code for creating a character array containing...
How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine...
We would like to align two DNA sequences: (v) C G A T A C T,...
We would like to align two DNA sequences: (v) C G A T A C T, and (w) G A T T C G T : i) s(i, j) = 1.5 if vi = wj (matches); ii) s(i, j) = -1.0 if vi != wj (mismatches); iii) d = 0.25 (indels: insertions or deletions). What would be the maximum alignment score? Explain how you get the result.
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
Below are sets of three variables. On the lines after each set, do the following: Write...
Below are sets of three variables. On the lines after each set, do the following: Write a hypotheses relating the first two variables. Identify independent and dependent variables. State how you expect the third variable to affect the hypothesized relationship. Draw an arrow diagram including all three variables. Determine whether the third variable is antecedent, intervening, or alternative. Primary caregiver for children (primary caregiver, not primary caregiver); support for Family Medical Leave Law (thermometer scale for support); gender (female, male)...
Write a program that allows the user to enter two integers and a character If the...
Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT