Question

In: Computer Science

Write a code to ask for a vector with 10 elements from the user and replace...

  1. Write a code to ask for a vector with 10 elements from the user and replace the 1st, 3rd, 8th  to 9th  elements with the second element of the given vector. (you can insert a vector when you use input function)

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<iostream>

#include<vector>

using namespace std;

void input(vector<int> &v){

    cout<<"Enter 10 values: ";

    int val;

    for(int i=0; i<10; i++){

        cin>>val;

        v.push_back(val);

    }

}

int main(){

    vector<int> v;

    input(v);

    cout<<"The entered vector data is:";

    for(int i=0; i<v.size(); i++){

        cout<<" "<<v[i];

    }

    cout<<"\n\nThe second element is: "<<v[1]<<endl;

    v[0] = v[1];

    v[2] = v[1];

    v[7] = v[1];

    v[8] = v[1];

    cout<<"\n\nAfter replacing with second element, the vector is:"<<endl;

    for(int i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    return 0;

}


Related Solutions

Write a java code to ask the user for a string, and assuming the user enters...
Write a java code to ask the user for a string, and assuming the user enters a string containing character "a", your java program must convert all "a" to "b" in the string so for example if user types : "AMAZON" , your program must convert it to "BMBZON" the driver program must ask : enter a string containing "a" or "A" --------- (user enters string) then it should say; HERE IS YOUR NEW STRING ---------- (string with all a's...
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
This assignment asks to create an array with 10 integer elements. Ask user to input 10...
This assignment asks to create an array with 10 integer elements. Ask user to input 10 integer values. going through all the array elements and find/print out all the prime numbers. Instructions: Only use for loops for this lab (no need to create methods or classes for this assignment). Put a comment on each line of your codes, explaining what each line of code does. basic java, please
Write a Python code that will ask a user to input a year and return "Leap...
Write a Python code that will ask a user to input a year and return "Leap Year" if the year is a leap year, or "No Leap Year" if it is not a leap year. The program then asks for another year and performs the same task in the form of a loop, until the user inputs the then integer "-1." At that point, the program will exit the loop.
Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
1. Write Python code to - (a) ask user to enter a list of animals, one...
1. Write Python code to - (a) ask user to enter a list of animals, one item at a time, until “done” to terminate input (b) randomly display a selected item from the list, starting with “I like ______”. When run, the output should look something like this: Enter an item; 'done' when finished: cats Enter an item; 'done' when finished: dogs Enter an item; 'done' when finished: guinea pigs Enter an item; 'done' when finished: done You are done...
Please code in c# (C-Sharp) Write a program that will ask the user for their name....
Please code in c# (C-Sharp) Write a program that will ask the user for their name. If the user does not input anything, display a warning before continuing. The program will then ask the user whether they want to have an addition, subtraction, multiplication, or division problem. Once the user indicates their choice, the program will display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice. Example: user selects addition, the equation presented...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT