Create HiArrayString class to store string values
Note: language used is C++
I have performed the input and output in main only as there was nothing specified whether to create functions or not in the class.
#include <iostream>
#include<vector>
#include<string>
using namespace std;
//class to store strings
class HiArrayString{
public:
vector<string> v;
};
int main() {
HiArrayString st;
cout<<"Enter the number of strings: ";
int n;
cin>>n;
//we use 1 extra input to consume 1 '\n' that will be pressed after
user enters the value of n. So loop from =0 to =n i.e. n+1
strings
for(int i=0; i<=n; i++)
{
string s;
//get the string from user
getline(cin,s);
//store the string in the vector
st.v.push_back(s);
}
cout<<"\nThe strings stored are: ";
//iterate through the vector to get the output
for(auto i:st.v)
{
cout<<i<<endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.