In: Computer Science
In C++ Programming Language:
1a. Declare a class, namely ReverseUniverse, that contains three public member functions. Please see Q2 and Q3 for the name of the second and third function. (5 points)
Write a function string reverseString that reverses a string (first member function). It takes a string parameter and returns its reversed version. (10 points)
1b. In the class ReverseUniverse in Q1. Write a function vector reverseVector that reverses a vector (second member function). It takes a double vector parameter and returns its reversed version.
1b. In the class ReverseUniverse in Q1. Write a function int reverseInt that reverses an integer (third member function). It takes an int parameter and returns its reversed version.
NOTE: 1. You are NOT allowed to: i. convert int to string, ii. use vector or array. 2. Feel free to define helper member functions if needed.
Explanation:
here is the code with all the member functions in the class ReverseUniverse
Code:
#include <iostream>
#include <vector>
using namespace std;
class ReverseUniverse
{
public:
int reverseInt(int i)
{
int reversed = 0;
while(i>0)
{
reversed = reversed*10 + i%10;
i/=10;
}
return reversed;
}
vector<double> reverseVector(vector<double> v)
{
int start = 0, end = v.size()-1;
while(start<end)
{
double temp = v[end];
v[end] = v[start];
v[start] = temp;
start++;
end--;
}
return v;
}
string reverseString(string s)
{
int start = 0, end = s.length()-1;
while(start<end)
{
char temp = s[end];
s[end] = s[start];
s[start] = temp;
start++;
end--;
}
return s;
}
};
int main()
{
return 0;
}
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!