in C++ // praphrase or change this code , while the purpose and output is same .
#include <iostream>
#include <stdint.h>
using namespace std;
class arr{
private:
int size_arr; //To store the size of the array
char *begin; //Pointer for dynamic allocation of memory
int capacity; //To store the capacity of the elements in the array
public:
arr(int n); //constructor (default) for creating an array
int insert_arr(char x); //To insert an element x in the array
int remov_arr(int i); //To remove an element from position i
void display();
void displayAtPos(int i);//Function to display a character at position i
};
arr::arr(int n){
size_arr = n;
begin = new char[size_arr];
capacity = 0;
}
int arr::insert_arr(const char x){
if(capacity >= size_arr){
cout << "Array Full!" << endl;
return -1;
}
begin[capacity++] = x; //One element is added, so increment the capacity by one.
return 0;
}
int arr::remov_arr(int i){
if(capacity == 0){
cout << "Nothing to delete " << endl;
return -1;
}
if(capacity < i || i < 0){
cout << "Out of bound" << endl;
return -1;
}
if(capacity == 1){
begin[capacity] = '\0';
capacity--;
return 0;
}
for(int j = i;j < capacity;j++){
begin[j] = begin[j+1]; //Shift each element towards one place before
}
begin[capacity] = '\0'; //change the duplicate character in the end to a null character.
capacity--; //One element is removed, so decrement the capacity by one.
return 0;
}
void arr::display(void){
for(int i = 0;i < capacity;i++){
cout << begin[i];
}
cout << endl;
}
void arr::displayAtPos(int i){
if(begin[i] == '\0')
cout << "Null character\n";
else{
cout << begin[i] << endl;
}
}
int main()
{
int n;
arr obj1(26);
obj1.insert_arr('A');
obj1.insert_arr('B');
obj1.insert_arr('C');
obj1.insert_arr('D');
obj1.insert_arr('E');
obj1.insert_arr('F');
obj1.insert_arr('G');
obj1.insert_arr('H');
obj1.insert_arr('I');
obj1.insert_arr('J');
obj1.insert_arr('K');
obj1.insert_arr('L');
obj1.insert_arr('M');
obj1.insert_arr('N');
obj1.insert_arr('O');
obj1.insert_arr('P');
obj1.insert_arr('Q');
obj1.insert_arr('R');
obj1.insert_arr('S');
obj1.insert_arr('T');
obj1.insert_arr('U');
obj1.insert_arr('V');
obj1.insert_arr('W');
obj1.insert_arr('X');
obj1.insert_arr('Y');
obj1.insert_arr('Z');
obj1.display();
cout << "Enter element number to be erased(0 to 25) :";
cin >> n;
obj1.remov_arr(n);
cout << "After Removing item at position " << n << " :" << endl;
obj1.display();
cout << "Data at last element is :";
obj1.displayAtPos(25);
return 0;
}
Step by stepSolved in 2 steps with 1 images
- Topic: pointers, dynamic array and command line arguments Write a complete C++ program named “showHelp” that accepts command line arguments. It checks whether there is a command line argument of “/help” or“/?” or “-help” followed by a topic number. It will print out “yes, topic number(<number>) if there is one. Otherwise, it prints out “no, topic number(N/A) For example, if you run this program with correct arguments as follows, it willprint out yes and its associated topic number respectivelyshowHelp /? 101showHelp /debug /help 102showHelp /print /help 103 /verboseshowHelp -verbose -debug -help And if you run the program with invalid arguments, it will print no, in all casesshowHelp -helpshowHelp 101 /?showHelp 101 102 /help /verboseshowHelp /? /help -helpNote: command line arguments are simply an array of pointers to C-string. example code: #include <iostream> using namespace std; int main(int argc, char** argv){...}arrow_forwardc++ coding language I need help with part B and C please. If you are unable to do both, then PLEASE prioritize part C. I am really stuck and really can use the help. This is the code for c that was provided in order to guide me: const int N =31; // N parking spaces bool parking[N]; // the garage void EmptyTheLot(bool parking[], int N) { for(int i=0; i<N; i++) p[i]=false; // empty space } // returns -1 if no space found, //otherwise it returns 0<=i<N for a valid space. int FindSpace(int PlateNumber, bool parking[], int N) { // ????? } main() { EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot. }arrow_forwardAHPA #10:The Secure Array(use C programming)• A programmer that you work with, Peter, is a jerk.• He is responsible for an array [theArray] that is a key part of an importantprogram and he maintains a sum of the array values at location [0] in the array.• He won't give you access to this array; however, your boss has told you that youneed to get input from the user and then place it into the array.• Each evening Peter will scan the code and remove any illegal references to hisarray.• Using pointers, access Peter's array without him knowing it and place threevalues that you got from the user (101, 63, 21) at locations 3, 6, and 9.Recalculate the sum value and update it. ( the output should be same as the picture)arrow_forward
- C++, Please add a function where it can display the median, the maximum number, the minimum number, in an array entered by the user. Code: #include<iostream> using namespace std; class Search_Dynamic_Array { public: Search_Dynamic_Array(); int getArrSize(); void getArray(); void setArrsize(int); void setArray(int*); int getSum(int*); private: int arr_size; int arr[]; }; Search_Dynamic_Array::Search_Dynamic_Array() { //ctor } int Search_Dynamic_Array::getArrSize() { return arr_size; } void Search_Dynamic_Array::getArray() { cout << "The elements of the array are: "; for(int i=0; i<arr_size; i++){ cout << arr[i] << " "; } } void Search_Dynamic_Array::setArrsize(int s) { arr_size=s; } void Search_Dynamic_Array::setArray(int a[]) { for(int i=0; i<arr_size; i++){ arr[i]=a[i]; } } int Search_Dynamic_Array::getSum(int a[]) { int sum; for(int i=0; i<arr_size; i++){ sum +=arr[i]; } return sum; } int main() { int s=1, a[s]; cout << "Enter the size of the…arrow_forwardC++ Find 2D array max and min. Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles.Ex: If the input is:-10 20 30 40the output is:Min miles: -10 Max miles: 40 #include <iostream>using namespace std; int main() { const int NUM_ROWS = 2; const int NUM_COLS = 2; int milesTracker[NUM_ROWS][NUM_COLS]; int i; int j; int maxMiles = 0; // Assign with first element in milesTracker before loop int minMiles = 0; // Assign with first element in milesTracker before loop int value; for (i = 0; i < NUM_ROWS; i++){ for (j = 0; j < NUM_COLS; j++){ cin >> value; milesTracker[i][j] = value; } } for(i = 0; i <= NUM_ROWS; i++) { for(j = 1; j <= i; j++) { cout << ""; } } cout << "Min miles: " << minMiles << endl; cout << "Max miles: " << maxMiles << endl; return…arrow_forwardTwo dimension array in C:Create a two dimension array of integers that is 5 rows x 10 columns.Populate each element in the first 2 rows (using for loops) with the value 5.Populate each element of the last three rows (using for loops) with the value 7.Write code (using for loops) to sum all the elements of the first three columns and output thesum to the screen. without using #definearrow_forward
- C++arrow_forwardIn C++ Create an array of head pointers, statically allocated of size 101 of that type: Now, create a pointer that can point to the first element: Show how to dynamically allocate an array of 101 elements of head pointers: Write the code to initialize each element to NULL: Rewrite the code to initialize each element to NULL using pointer arithmetic:arrow_forwardC++ Coding Assignment: Redo the 8 queens 1-dimensional array program with backtracking by REMOVING ALL GOTO's, but implementing the same algorithm. GIVEN C++ CODE - WITH GOTO's: #include <iostream>using namespace std; int main() { int q[8], c=0; q[0] = 0; // place a queen in row 0 of column 0 int counter = 0; // to count solutions // c: column as q[c]: row in column c next_col: ++c; // or c++; // next column if(c==8) goto print; q[c]=-1; // 0 next_row: ++q[c]; // or q[c]++; // next row if(q[c]==8) goto backtrack; for(int i=0; i<c; ++i) if(q[i]==q[c] || (c-i)== abs(q[c]-q[i])) // || = row test OR diagonal tests goto next_row; goto next_col; backtrack: --c; // or c-- if(c==-1) // once we backtrack to column -1, we have all the solutions. return 0; // ends the program goto next_row; print: counter++; // new solutions cout << counter << ":" << endl; for(int…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education