Question #175405

Write a program to get an integer from the user (to enter the number of students) and store it in the num variable. Then, allocate the memory dynamically for the float array using new operator. Next enter data(student register number) into the array using pointer notation. Arrange register number from lower to highest. After this you no longer need the array, so deallocate the array memory using the delete operator.


Expert's answer

#include <algorithm>
#include <iostream>
int main()
{
    int num;
    std::cout << "Enter the size of the array:" << std::endl;
    std::cin >> num;
    float* array = new float[num];
    for (int i = 0; i < num; i++)
    {
        std::cout << "Enter registration number "<<i+1<< "of the student:" << std::endl;
        std::cin >> array[i];
    }
    std::sort (array, array + num);
    delete array;
    array = nullptr;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS