Question

Create a new file (in Dev C++) Modify program above to use a vector instead of...

Create a new file (in Dev C++)

Modify program above to use a vector instead of an array.

  • Header comments must be present
  • Prototypes must be present if functions are used
  • Hello and goodbye messages must be shown
  • Vector(s) must be used for implementation
  • Use comments and good style practices
======================================================================================================
#include <iostream>

using namespace std;

int main() {

cout<<"Welcome! This program will find the minimum and maximum numbers in an array."<<endl;

cout<<"You will be asked to enter a number ten times. Then, the program will display"<<endl;

cout<<"the numbers back to you and indicate which is the smallest and which is the largest."<<endl<<endl;

int arr[10],min=1000,max=-1;

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

cout<<"Please enter a number: ";

cin>>arr[i];

if(min>arr[i])

min=arr[i];

if(max<arr[i])

max=arr[i];

}

cout<<"\nValues: ";

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

cout<<arr[i]<<" ";

cout<<"\nMinimum: "<<min<<endl;

cout<<"Maximum: "<<max<<endl;

cout<<"\nExiting program. Goodbye!";

}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <vector>

using namespace std;

void hello();

void goodbye();

void printVector(vector<int> v);

int minVector(vector<int> v);

int maxVector(vector<int> v);

int main() {
    int num;
    vector<int> v;
    hello();
    for (int i = 0; i < 10; i++) {
        cout << "Please enter a number: ";
        cin >> num;
        v.push_back(num);
    }
    printVector(v);
    cout << "\nMinimum: " << minVector(v) << endl;
    cout << "Maximum: " << maxVector(v) << endl;
    goodbye();
}

void hello() {
    cout << "Welcome! This program will find the minimum and maximum numbers in an array." << endl;
    cout << "You will be asked to enter a number ten times. Then, the program will display" << endl;
    cout << "the numbers back to you and indicate which is the smallest and which is the largest." << endl << endl;
}

void goodbye() {
    cout << "\nExiting program. Goodbye!";
}

void printVector(vector<int> v) {
    cout << "\nValues: ";
    for (int i = 0; i < 10; i++)
        cout << v[i] << " ";
    cout << endl;
}

int minVector(vector<int> v) {
    int num = v[0];
    for (int i = 0; i < v.size(); ++i) {
        if (v[i] < num)
            num = v[i];
    }
    return num;
}

int maxVector(vector<int> v) {
    int num = v[0];
    for (int i = 0; i < v.size(); ++i) {
        if (v[i] > num)
            num = v[i];
    }
    return num;
}
Add a comment
Know the answer?
Add Answer to:
Create a new file (in Dev C++) Modify program above to use a vector instead of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp...

    Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp Is posted here: // This program reads data from a file into an array. Then, it // asks the user for a number. It then compares the user number to // each element in the array, displays the array element if it is larger. // After looking at entire array, it displays the number of elements in the array larger // than the user...

  • In c++ programming, can you please edit this program to meet these requirements: The program that...

    In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; }    while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...

  • /* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector>...

    /* Implementation of the main() method of the program. */ #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class Student { public:    // default constructor    Student()    {        studentID = 0;        studentFirst = "First";        studentMiddle = "Middle";        studentLast = "Last";    }    void SetStudentID(int number) { studentID = number; }    void SetStudentFirst(string name) { studentFirst = name; }    void SetStudentMiddle(string name) { studentMiddle =...

  • Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0,...

    Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0, ave-ee, int locmx, locmn int n; cout <<"Enter the number of students: "<<endl; cin >> ni double listln]; double max-0; double min-e; for (int i-e ; i<n ;i++) cout<s enter the gpa: "<cendli cin>>listli]; while (listlile i listli1>4) cout<s error,Try again "<cendl; cin>listlil: sun+=list[i]; N1 if (listli]>max) for(int isin itt) max=list [i]; 10cmx=1+1 ; else if (list [i] min) min=list [i]; locmn-i+1; ave sum/n;...

  • please Code in c++ Create a new Library class. You will need both a header file...

    please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h>...

    I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h> #include <windows.h> using namespace std; int main() { int m, s,h; cout << "A COUNTDOWN TIMER " << endl; cout << "enter time in hours here" << endl; cin >> h; cout << "enter time in minutes here " << endl; cin >> m; cout << "enter time in seconds here" << endl; cin >> s; cout << "Press any key to start" <<...

  • Q2. Consider the following C++ program that declares, allocates and fills in a1D array with random...

    Q2. Consider the following C++ program that declares, allocates and fills in a1D array with random numbers between 0 and 100. The array is sent to a function that finds the indices of all items > 50. A new array is created and the indices are stored inside it. The size of the new arrays MUST BE the same as the number of items > 50. The function returns the new array which is then printed out by main. Here...

  • Write a simple telephone directory program in C++ that looks up phone numbers in a file...

    Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...

  • The following C++ code has a problem where the loop can exceed the size of the...

    The following C++ code has a problem where the loop can exceed the size of the array if the user inputs too many numbers. #include <iostream> using namespace std; int main() { int nums[20] = { 0 }; int a[10] = { 0 }; cout << a << endl; cout << nums << endl; cout << "How many numbers? (max of 10)" << endl; cin >> nums[0]; for (int i = 0; i < nums[0]; i++) { cout << "Enter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT