#include<iostream>
#include<conio.h>
using namespace std;
class CoolString
{
private:
int n;
char *array;
public:
void accept();
void display();
void reverse();
~CoolString();
};
void CoolString::accept()
{
cout << "Enter no. of elements:" <<
endl;
cin >> n;
array=new char[n];
cout << "Enter the Characters in the
array:";
for (int index = 0; index < n; index++)
{
cin >> array[index];
}
}
void CoolString::display()
{
cout << "Values in the array are:";
for (int index = 0; index < n; index++)
{
cout <<"\t"<<
array[index];
}
}
void CoolString::reverse()
{
char temp;
int m = n-1;
for (int index = 0; index < n/2; index++,m--)
{
temp = array[m];
array[m] = array[index];
array[index] = temp;
}
}
CoolString::~CoolString()
{
delete[] array;
}
int main()
{
CoolString cs;
cs.accept();
cs.display();
cs.reverse();
cout << endl;
cs.display();
_getch();
return 0;
}
=============================OUTPUT======================================


//If found useful,Please Upvote!!!!!!!!!
C++ programing 1. [10pts] Assume you are adding a new method to the CoolString class called...
Write a method called printReverse() that
takes a string and uses recursion to print the contents of the
string in reverse order. The string itself should
not be reversed; it must be left in its
original form.
The method has the following header:
void printReverse(String s, int i)
where s is a reference to the string, and i is an integer
parameter that you may use as you see fit. You do not need
to code up this method as...
1. Create a new class called ReversibleArray. 2. In the class header, add the code <T> immediately to the right of the class name. 3. Give this class two private instance variables: T[] array and int count 4. Create a constructor which takes in one parameter of type T[] and assign that parameter's value into this.array. Set count as the length of the array. 5. Add a toString() method that outputs the array values in the format: elem0, elem1, elem2,...
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...
please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...
Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...
Assume that we are writing a game like Minecraft in C++. We will have a World class that stores a 3-dimensional array of "Voxels". A voxel is a simple element of volume (think Pixel, but 3D). Your task for this assignment is to create a world, set some Voxels and display them. You are provided with a simple class for a Voxel that stores a RGB color value, as well as a character code for the type of element. You...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...
C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...
1. Here are codes to define a stack class based on dynamic array, please complete the copy constructor //--- Definition of Stack copy constructor Stack::Stack(const Stack & original) : myCapacity(original.myCapacity), myTop(original.myTop) { //--- Get new array for copy myArray = new(nothrow) StackElement[myCapacity]; if (myArray != 0) // check if memory available // copy original's array member into this new array { // Please complete the function here } else { cerr << "*Inadequate memory to allocate...