Write an interactive C++ program which prompts the user for 10 integers (one at a time) and stores them into a one dimensional array and prints the result. Then the program takes the array and reverses the order of its elements and prints the reversed array. The following is an example of reversing elements of an array.Program requirements:
- The program must contain a class in which all the required private and public identifiers and the following functions must be defined.

- The program must contain three or more functions using parameters

Note:
- At least one of the above functions and identifiers should be private.

Dani AI

Generated

A focused fix and a compact example.

The task is to read 10 integers into a one‑dimensional container, print them, then reverse the order and print again, with the logic wrapped in a class that exposes public and private identifiers and at least three functions that take parameters. made a good effort, but the routine named sortReverse actually sorts the array by value (bubble sort) instead of reversing the element order — sorting is the wrong algorithm for this requirement. Also avoid non‑standard void main(); prefer int main() and perform simple bounds checks when writing into the array.

A minimal, correct class-based pattern (meets “three or more functions with parameters” and includes a private helper) is shown below:

#include <iostream>
#include <vector>

class IntReverser {
public:
    explicit IntReverser(std::size_t n = 10) : data(n) {}

    void setAt(std::size_t idx, int value) {
        if (idx < data.size()) data[idx] = value;
    }

    int getAt(std::size_t idx) const {
        return (idx < data.size()) ? data[idx] : 0;
    }

    void printAll(std::ostream& os = std::cout) const {
        for (std::size_t i = 0; i < data.size(); ++i)
            os << data[i] << (i + 1 < data.size() ? ' ' : '\n');
    }

    void reverseAll() { reverseRange(0, data.size() ? data.size() - 1 : 0); }

private:
    std::vector<int> data;

    void reverseRange(std::size_t s, std::size_t e) {
        while (s < e) { int t = data[s]; data[s++] = data[e]; data[e--] = t; }
    }
};

int main() {
    IntReverser A;
    for (std::size_t i = 0; i < 10; ++i) { int x; if (!(std::cin >> x)) return 1; A.setAt(i, x); }
    A.printAll();
    A.reverseAll();
    A.printAll();
    return 0;
}

Notes and quick troubleshooting:

  • The correct operation to meet the brief is an in‑place reversal (swap first/last, second/second‑last, ...). Sorting changes values’ relative ordering and fails the requirement.
  • Guard index writes (shown above) to avoid overruns.
  • Prefer std::vector or std::array over raw pointers for safety.
  • The class above provides public functions that take parameters (setAt, getAt, printAll) and a private parameterized helper (reverseRange), so it satisfies the stated constraints while keeping the intent clear. This keeps the learning focused on array indexing and in‑place algorithms rather than on sorting.

Recommended Answers

All 9 Replies

This looks just like the last question you asked. what don't you understand about it?

#include<iostream>

using namespace std;

const int element = 10;

class solution {

	public:
		solution();
		void store (int, int);
		void print(int &, int );
		void sortReverse();

	private:
		int num[element];

};
	
solution::solution(){

	for (int i=0; i<element; i++){
		num[i] = 0;

	}

}

void solution::store(int a, int j){

	num[j] = a;
}

void solution::sortReverse(){

	int temp = 0;

	for(int i=0; i<element; i++){
		for(int j=0; j<element-1; j++)
			if(num[j]<num[j+1]){
				temp = num[j];
				num[j] = num[j+1];
				num[j+1] = temp;

			}

	}

}

void solution::print(int &a, int index){

	a = num[index];
	

}
	
void main(){
	
	int count = 0, num3 = 0, a;
	solution A;
	
	do{
		cout<<"Please enter an integer: ";
		cin>>num3;
		cout<<endl;

		//storing the array using parameter
		A.store(num3,count);

		count ++;

	}while(count<10);

	// Reversing elements of an array
	
	A.sortReverse();

	//Printing the array using parameter
	
	cout<<"Printing the reverse array."<<endl;

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

		A.print(a, i);

		cout<<a<<" ";

	}

	cout<<endl;

}
Member Avatar for Member #46692

Don't do other people's homework. Period.

:cool:

Yes i think thats correct but to help someone is not wrong

Yes i think thats correct but to help someone is not wrong

True -- but the OP didn't ask for our help, just stated a problem.:rolleyes:

And besides, doing someone's homework for them isn't actually helping them learn, They're just given the answer with no real understanding gained.

commented: Absolutely! +1

K.......I agree with u.

Ok Can u please help me i swear this is not my homework and only a creation of mine.please help is therein help....lib management program...:rolleyes:
I have created it on my own i swear:eek:

Ok Can u please help me i swear this is not my homework and only a creation of mine.please help is therein help....lib management program...:rolleyes:
I have created it on my own i swear:eek:

Cool -- why are you hijacking this thread? you already have your own thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.