Question

In: Computer Science

Write an interactive program in c++ that allows the user toenter 2-15 vectors (use the...

Write an interactive program in c++ that allows the user to enter 2-15 vectors (use the if statement). Display the resultant on the screen.

Solutions

Expert Solution

Code

#include 
#include 

using namespace std;

//to print
void display(const vector>& V) {
    for (auto & i : V) {
        for (int j : i) {
            cout << j << " ";
        }
        cout << "\n";
    }
}

int main() {
    //to store vectors
    vector> V;
    int value ;
    // to enter the number of vectors user wants
    cout<<"Enter the number of vector you want to add between 2-15";
    cin >> value;
    int i = 0;
    // to store the value in each vector 
    while (i < value && value >= 2 && value <= 15 ) {
        vector v;
        string val;
        cout << "Press null to stop entering integers in current vectors" << "\n";
        cin >> val;
        // when to stop storing value in particular vector
        do {
            v.push_back(stoi(val));
            cin >> val;
        } while (val != "null");
        V.push_back(v);
        i++;

    }
    // printing result
    display(V);
    return 0;
}

Output


Related Solutions

Write an interactive C program that asks a user to enter a sentence from the keyboard,...
Write an interactive C program that asks a user to enter a sentence from the keyboard, and prints the sentence with all the words spelled backwards. Note: you may assume that each sentence will have at most 50 characters and each word is separated by a space. Sample code execution: bold information entered by user enter a sentence: hello ece 175 class olleh ece 571 ssalc continue (q to quit)? y enter a sentence: May the force be with you...
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Use Visual Python or equivalent, to write a program that allows the user to observe the...
Use Visual Python or equivalent, to write a program that allows the user to observe the following: Damped and forced harmonic oscillators. The program should be user friendly and have default values for the initial velocities, positions, masses, and spring constants as well as damping constants. Values and frequencies for the forced oscillators should also be given. It should allow the user to input values for the velocities, positions, spring constants, and masses. The program should determine automatically the scale...
Write a C program with the following prompt *do not use gotostatement* "Write an interactive...
Write a C program with the following prompt *do not use goto statement* "Write an interactive program that implements a simple calculator. The program should allow the user to choose a binary arithmetic operation and enter two terms to which to apply the operation. The program should then compute the result and display it to the user. Your calculator will have two modes: double-precision mode and integer mode. Double-precision mode will do calculations and output using variables of type double....
write a complete C++ program that allows the user to choose from one of several options....
write a complete C++ program that allows the user to choose from one of several options. The program will display a menu and each option will be in a separate function. The program will continue looping until the user chooses to quit. The module descriptions are given below. a. Prompt for and take as input 3 floating point values (l, w, and h). The program will then calculate the volume (volume = l*h*w ). The program should then output to...
Write a C++ program that allows a user choose item to purchase from a list; ask...
Write a C++ program that allows a user choose item to purchase from a list; ask for the amount to calculate the cost of the purchase; offer to add a tip; add a delivery fee based on the subtotal; then calculate the total amount that the user needs to pay. ---------------------------------- ----- GROCERY SHOPPING ITEMS ----- Milk     - $5.99 / gallon Egg      - $6.99 / dozen Cheese   – $10.98 / 8oz Pasta    – $2.75 / packet ---------------------------------- Other Values to...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by that candidate. The program should then output each candidates name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follow Johnson    5000 25.91 miller    4000   ...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user for the number of interior and exterior murals scheduled to be painted during the next month by Marshall’s Murals. Next, the programs compute the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. The application also displays the total expected revenue and a statement that indicates whether more interior murals are scheduled than exterior...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q (4) Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT