Write a program which prompts the user to enter up to 15 floating point numbers (terminated with a non-numeric), reads them into an array, then prints the following. The program must use an array (not a vector) to get credit. The array values in the original order, separated by commas, with no trailing comma at the last value. The array values where the order of each adjacent pair of elements is swapped, separated by commas (NOT every element swapped with its next neighbor, which would just move the first element to the end, but every original pair swapped only in that pair. For an odd element count, the last element should not change. See examples below.) The smallest number in the array. Example program outputs with user input shown in bold font: Enter up to 15 numbers, and a non-numeric to quit: 1 0 -1.001 # Original array: 1, 0, -1.001 The swapped array: 0, 1, -1.001 Smallest number: -1.001 Enter up to 15 numbers, and a non-numeric to quit: 1 0 -1.001 5 , Original array: 1, 0, -1.001, 5 The swapped array: 0, 1, 5, -1.001 Smallest number: -1.001 provide some comments for code.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter10: Pointers
Section: Chapter Questions
Problem 5PP
icon
Related questions
Question

1

Write a program which prompts the user to enter up to 15 floating point numbers (terminated with a non-numeric), reads them into an array, then prints the following. The program must use an array (not a vector) to get credit.

  • The array values in the original order, separated by commas, with no trailing comma at the last value.
  • The array values where the order of each adjacent pair of elements is swapped, separated by commas (NOT every element swapped with its next neighbor, which would just move the first element to the end, but every original pair swapped only in that pair. For an odd element count, the last element should not change. See examples below.)
  • The smallest number in the array.

Example program outputs with user input shown in bold font:

Enter up to 15 numbers, and a non-numeric to quit:

1 0 -1.001 #

Original array: 1, 0, -1.001 The swapped array: 0, 1, -1.001 Smallest number: -1.001 Enter up to 15 numbers, and a non-numeric to quit:

1 0 -1.001 5 ,

Original array: 1, 0, -1.001, 5 The swapped array: 0, 1, 5, -1.001 Smallest number: -1.001

provide some comments for code.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

this is insturction

Write a program which prompts the user to enter up to 15 floating point numbers (terminated with a non-numeric), reads them into an array, then prints the following. The program must use an array (not a vector) to get credit.

  • The array values in the original order, separated by commas, with no trailing comma at the last value.
  • The array values where the order of each adjacent pair of elements is swapped, separated by commas (NOT every element swapped with its next neighbor, which would just move the first element to the end, but every original pair swapped only in that pair. For an odd element count, the last element should not change. See examples below.)
  • The smallest number in the array.

Example program outputs with user input shown in bold font:

Enter up to 15 numbers, and a non-numeric to quit:

1 0 -1.001 #

Original array: 1, 0, -1.001 The swapped array: 0, 1, -1.001 Smallest number: -1.001 Enter up to 15 numbers, and a non-numeric to quit:

1 0 -1.001 5 ,

Original array: 1, 0, -1.001, 5 The swapped array: 0, 1, 5, -1.001 Smallest number: -1.001

provide some comments for code and must done c++

I am getting errors and attached the picture. Could you check please and fix the error? thanks. 

this code 

#include <iostream>
using namespace std;

int main() {
 ,const,  const int maxSize = 15;
    double numbers[maxSize];
    int count = 0;


    // Read input numbers until non-numeric input or reaching the maximum size of the array
    while (count < maxSize && cin >> numbers[count]) {
        count++;
    }

    cout << "Original array: ";

    // Print the original array values separated by commas
    for (int i = 0; i < count; i++) {
        cout << numbers[i];
        if (i < count - 1) {
            cout << ", ";
        }
    }

    cout << endl << "The swapped array: ";

    // Print the array values where each adjacent pair of elements is swapped, except for the last element (if the count is odd)
    for (int i = 0; i < count - 1; i += 2) {
        cout << numbers[i + 1] << ", " << numbers[i];
        if (i + 2 < count - 1) {
            cout << ", ";
        }
    }
    // Print the last element if the count is odd
    if (count % 2 != 0) {
        cout << ", " << numbers[count - 1];
    }

    // Find the smallest number in the array
    double smallest = numbers[0];
    for (int i = 1; i < count; i++) {
        if (numbers[i] < smallest) {
            smallest = numbers[i];
        }
    }

    cout << endl << "Smallest number: " << smallest << endl;

    return 0;

Failed to compile
main.cpp: In function 'int main()':
main.cpp:10:2: error: expected primary-expression before ',' token
10, const, const int maxSize = 15;
I
main.cpp:10:3: error: expected primary-expression before 'const'
, const, const int maxSize 15;
10 I
I
main.cpp:11:20: error: 'maxSize' was not declared in this scope
11 I
double numbers [maxSize];
main.cpp:16:38: error: 'numbers' was not declared in this scope
16 I while (count < maxSize & & cin >> numbers [count]) {
|
=
main.cpp:24:17: error: 'numbers' was not declared in this scope
cout << numbers [i];
24 1
main.cpp:34:17:
34 I
main.cpp:41:25:
41 I
error: 'numbers' was not declared in this scope
cout << numbers [i+1] << ", " << numbers [i];
error: 'numbers' was not declared in this scope
cout << ", << numbers [count - 1];
main.cpp:45:23: error: 'numbers' was not declared in this scope
double smallest = numbers [0];
45 1
Transcribed Image Text:Failed to compile main.cpp: In function 'int main()': main.cpp:10:2: error: expected primary-expression before ',' token 10, const, const int maxSize = 15; I main.cpp:10:3: error: expected primary-expression before 'const' , const, const int maxSize 15; 10 I I main.cpp:11:20: error: 'maxSize' was not declared in this scope 11 I double numbers [maxSize]; main.cpp:16:38: error: 'numbers' was not declared in this scope 16 I while (count < maxSize & & cin >> numbers [count]) { | = main.cpp:24:17: error: 'numbers' was not declared in this scope cout << numbers [i]; 24 1 main.cpp:34:17: 34 I main.cpp:41:25: 41 I error: 'numbers' was not declared in this scope cout << numbers [i+1] << ", " << numbers [i]; error: 'numbers' was not declared in this scope cout << ", << numbers [count - 1]; main.cpp:45:23: error: 'numbers' was not declared in this scope double smallest = numbers [0]; 45 1
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage