Question

In: Computer Science

language c++ finish the code and hurry in an exam with less then 30 minutes #include...

language c++ finish the code and hurry in an exam with less then 30 minutes

#include <iostream>

#include <vector>

using namespace std;

int find(vector<int> & v, int value);

int main(){

vector<int> myVec = {2,30,10,50,100,32,19,43, 201, 311, 99,77,45,15,95, 105, 32, 15};

//complete code here

cout << "First Element is: " << endl;

cout << "Last Element is: " << endl;

cout << "The number of elements is: " << endl;

  

//Complete the missing code

cout << "Find 201 : result is at index " << endl;

cout << "Find 299 : result is at index " << endl;

  

return 0;

  

}

int find(vector<int> & v, int value){

//complete the code here

  

return -1;

}

  

  

  

  

return 0;

}

output should be like this

first element is : 2

Last element is :15

the number of element is :18

write a function find that takes in the vector and the value you would like to find

int find(vector<int)> & v, int value)

find 201: result is at index 8

find 299: result is at index -1

Solutions

Expert Solution

C++ CODE:

#include <iostream>
#include <vector>

using namespace std;

int find(vector<int> & v, int value);

int main(){
    vector<int> myVec = {2,30,10,50,100,32,19,43, 201, 311, 99,77,45,15,95, 105, 32, 15};
    //complete code here
    cout << "First Element is: " << myVec.at(0) << endl;
    cout << "Last Element is: " << myVec.at(myVec.size() - 1) << endl;
    cout << "The number of elements is: " << myVec.size() << endl;
    //Complete the missing code
    cout << "Find 201 : result is at index " << find(myVec, 201) << endl;
    cout << "Find 299 : result is at index " << find(myVec, 299) << endl;

    return 0;
}

int find(vector<int> & v, int value){
    //complete the code here
    for(int i = 0; i < v.size(); i++){
        if(v.at(i) == value)
            return i;
    }
    return -1;
}

OUTPUT:


Related Solutions

C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace...
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace std; AVLTree::AVLTree() { root = NULL; } AVLTree::~AVLTree() { delete root; root = NULL; } // insert finds a position for x in the tree and places it there, rebalancing // as necessary. void AVLTree::insert(const string& x) { // YOUR IMPLEMENTATION GOES HERE } // remove finds x's position in the tree and removes it, rebalancing as // necessary. void AVLTree::remove(const string& x) {...
Can someone covert the code into C language #include<iostream> #include<iomanip> #include<ios> using namespace std; /******************************************************************************** Function...
Can someone covert the code into C language #include<iostream> #include<iomanip> #include<ios> using namespace std; /******************************************************************************** Function name: main Purpose:                   main function In parameters: b,r,i Out paramters: trun,error,total,value Version:                   1.0 Author: ********************************************************************************/ void main() {    int i;//declaring this variable to get value for quitting or calaculating series    do {//do while loop to calaculate series until user quits        cout << "Enter 1 to evaluate the series." << endl;       ...
(LANGUAGE C++) This time, you will finish the program so that the user gets to solve...
(LANGUAGE C++) This time, you will finish the program so that the user gets to solve the puzzle. You will also use header files and introduce classes into your program. We will follow the draft start to how to incorporate classes. Here are the requirements: ·In the file quotes.h, define the Quotes class: o   Quotes(string filename) // a constructor to load quotes from the named file into a vector o   The vector should be a field of the class so it will...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; //...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; // constants const int FINAL_POSITION = 43; const int INITIAL_POSITION = -1; const int NUM_PLAYERS = 2; const string BLUE = "BLUE"; const string GREEN = "GREEN"; const string ORANGE = "ORANGE"; const string PURPLE = "PURPLE"; const string RED = "RED"; const string YELLOW = "YELLOW"; const string COLORS [] = {BLUE, GREEN, ORANGE, PURPLE, RED, YELLOW}; const int NUM_COLORS = 6; // names...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Projectile motion with air resistance code in c language
Projectile motion with air resistance code in c language
Please Write Code in C++ and include the correct #include <header> and not a catchall such...
Please Write Code in C++ and include the correct #include <header> and not a catchall such as bits/stdc: Write a recursive, string-valued function, replace, that accepts a string and returns a new string consisting of the original string with each blank replaced with an asterisk (*) Replacing the blanks in a string involves: Nothing if the string is empty Otherwise: If the first character is not a blank, simply concatenate it with the result of replacing the rest of the...
Can you write the shell scripts for these C files (code in C): #include <stdio.h> #include...
Can you write the shell scripts for these C files (code in C): #include <stdio.h> #include <string.h> #include <ctype.h> int main(int argb, char *argv[]){ char ch; int upper=1; if(argb>1){ if(strcmp(argv[1],"-s")==0){ upper=1; } else if(strcmp(argv[1],"-w")==0){ upper=0; } } while((ch=(char)getchar())!=EOF){ if(upper){ printf("%c",toupper(ch)); } else{ printf("%c",tolower(ch)); } } return 0; } ======================================================== #include <stdio.h> #include <stdlib.h> int calcRange(int array[],int size){ int max=array[1]; int min=array[0]; int a=0; for(a=1;a<size;a++){ if(array[a]>max){ max=array[a]; } } for(a=1;a<size;a++){ if(array[a]<min){ min=array[a]; } } printf("%d-%d=%d\n",max,min,max-min); } int main(int arga, char **argv){...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT