Please read the question carefully, each part asked for implementation using arr
ID: 3919885 • Letter: P
Question
Please read the question carefully, each part asked for implementation using array,vector and stack.
Ex. 1Stack, vector, queue, and array 1. Write three C++ functions which read strings from the standard input and print them in the reverse order. The first program should be implemented using an array, the second one using a vector and the third one using a stack. Argue on the best choice in the README file. 2. Write three C++ functions which read strings from the standard input and print them in the input order. The first program should be implemented using an array, the second one using a vector and the third one using a queue. Argue on the best choice in the README file. Specifications Input: a single line containing space separated strings ·Output: a single line containing space separated strings Special rules: Add#include -assignment. h" - Do not include the main) function The function names should be exl_reverse array, ex1_ reverse_ vector, exlreverse stack, ex1_ordered_array, ex1 ordered_vector, and exl_ordered_queueExplanation / Answer
(1)assignment.h
#include<bits/stdC++.h>
using namespace std;
void ex1_reverse_array(char , int);
void ex1_reverse_vector(vector<char>);
void ex1_reverse_stack(stack<char>);
void ex1_ordered_array(char , int);
void ex1_ordered_vector(vector<char>);
void ex1_ordered_queue(queue<char>);
(2)assignment.cpp
#include "assignment.h"
//function to print reverse using array
void ex1_reverse_array(char arr[],int size){
cout<<"Reverse using array ";
for(int i=size-1;i>=0;i--)
cout<<arr[i];
cout<<" ";
}
//function to print reverse using vector
void ex1_reverse_vector(vector<char >v){
cout<<"Reverse using vector ";
int size=v.size();
for(int i=size-1;i>=0;i--)
cout<<v[i];
cout<<" ";
}
//function to print reverse using stack
void ex1_reverse_stack(stack<char>s){
cout<<"Reverse using stack ";
while(!s.empty()){
cout<<s.top();
s.pop();
}
cout<<" ";
}
//function to print ordered using array
void ex1_ordered_array(char arr[],int size){
cout<<"Ordered display using array ";
for(int i=0;i<size;i++)
cout<<arr[i];
cout<<" ";
}
//function to print ordered using vector
void ex1_ordered_vector(vector<char>v){
cout<<"Ordered display using vector ";
int size=v.size();
for(int i=0;i<size;i++)
cout<<v[i];
cout<<" ";
}
//function to print ordered using queue
void ex1_ordered_queue(queue<char>q){
cout<<"Ordered display using queue ";
while(!q.empty()){
cout<<q.front();
q.pop();
}
cout<<" ";
}
(3)main.cpp
#include "assignment.cpp"
int main(){
int size;
cout<<"Enter size of array ";
cin>>size;
char arr[size];
vector<char>v;
stack<char>s;
queue<char>q;
cout<<"Enter string of length "<<size<<" : ";
for(int i=0;i<size;i++){
cin>>arr[i];
v.push_back(arr[i]);
s.push(arr[i]);
q.push(arr[i]);
}
ex1_reverse_array(arr,size);
ex1_reverse_vector(v);
ex1_reverse_stack(s);
ex1_ordered_array(arr,size);
ex1_ordered_vector(v);
ex1_ordered_queue(q);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.