Answer to Question #175405 in C++ for Aditi

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.


1
Expert's answer
2021-03-25T08:27:32-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS