Question

#include <iostream>#include <string>using namespace std;// Implement printArray here// Implement deleteSmallest here//...

#include

#include

using namespace std;

// Implement printArray here

// Implement deleteSmallest here

// DO NOT CHANGE MAIN FUNCTION BELOW

int main() {

int myarray[100];

cout << "Enter number of integers : ";

int n;

cin >> n;

cout << "Enter " << n << " integers" << endl;

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

cin >> myarray[i];

cout << "Contents of array : ";

printArray(myarray, n);

deleteSmallest(myarray, n);

cout << "Contents of array after deleteSmallest: ";

printArray(myarray, n-1);

}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include
using namespace std;
// Implement printArray here

void printArray(int arr[], int size) {
   for(int i = 0; i < size; ++i) {
       cout << arr[i] << " ";
   }
   cout << endl;
}

// Implement deleteSmallest here
void deleteSmallest(int arr[], int size) {
   int index = 0;
   for(int i = 0; i < size; ++i) {
       if(arr[i] < arr[index]) {
           index = i;
       }
   }
   for(int i = index; i < size-1; ++i) {
       arr[i] = arr[i+1];
   }
}


// DO NOT CHANGE MAIN FUNCTION BELOW
int main()
{
    int myarray[100];
    cout << "Enter number of integers : ";
    int n;
    cin >> n;
    cout << "Enter " << n << " integers" << endl;
    for (int i = 0; i < n; i++)
        cin >> myarray[i];
    cout << "Contents of array : ";
    printArray(myarray, n);
    deleteSmallest(myarray, n);
    cout << "Contents of array after deleteSmallest: ";
    printArray(myarray, n - 1);
}

Add a comment
Know the answer?
Add Answer to:
#include <iostream>#include <string>using namespace std;// Implement printArray here// Implement deleteSmallest here//...
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
  • //Find two smallest integers #include <iostream> #include <string> using namespace std; // implement printArray here //...

    //Find two smallest integers #include <iostream> #include <string> using namespace std; // implement printArray here // implement findTwoSmallest here // DO NOT WRITE ANY CODE BELOW THIS LINE (EXCEPT FOR TESTING - REMOVE BEFORE SUBMITTING) int main() {     int n;     int arr[100];        cout << "Enter number of integers: ";     cin >> n;        cout << "Enter " << n << " integers: ";       for(int i = 0; i < n; i++) {        ...

  • #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int...

    #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int expected) { if (answer == expected) cout << "PASSED: " << testname << " expected and returned " << answer << "\n"; else cout << "FAILED: " << testname << " returned " << answer << " but expected " << expected << "\n"; } // Implement printArray here void printArray(int array[],int b) { for(int i = 0; i<b;i++) { std::cout<< array[i] << "...

  • int myarray[100]; cout << "Enter number of integers : "; int n; cin >> n; cout...

    int myarray[100]; cout << "Enter number of integers : "; int n; cin >> n; cout << "Enter " << n << " integers" << endl; for (int i = 0; i < n; i++)   cin >> myarray[i]; cout << "Contents of array : "; printArray(myarray, n);

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • One dimensional array What this code print #include <iostream> using namespace std; int main () {...

    One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << “Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << “ “; cout << endl; return 0; }

  • // PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); //...

    // PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...

  • #include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a...

    #include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a string to dashes string to_dash(string s){ for(int i = 0; i < s.length(); i++){ } return s; } int main(){ string s; cin >> s; s = to_dash(s); cout << s << endl; }

  • #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main()...

    #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main() { int size = 10; int * A = newZeroArray(size); for(int i = 0; i < size; i++) cout << A[i] << " "; cout << endl; }Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...

  • #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

    #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the array"<<endl;    cin>>SIZE;     int *numlist = new int[SIZE];     // Read SIZE integers from the keyboard     for (int i = 0; i<SIZE; i++ )    {        cout << "Enter value #" << i+1 << ": ";        cin >> numlist[i];     }     // Display the numbers in a reverse order     for (int i = SIZE; i > 0; i--...

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