Question

Create HiArrayString class to store string values

Create HiArrayString class to store string values

Homework Answers

Answer #1

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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a String object with the string: IT 206 is a GREAT class! Then, print if...
Create a String object with the string: IT 206 is a GREAT class! Then, print if the first letter of the string is an upper case letter.
Create a String object with the string: IT 206 is a GREAT class! Then, print out...
Create a String object with the string: IT 206 is a GREAT class! Then, print out if the character at index 7 is a digit or not using one of the following messages: Character is a digit! OR Character is not a digit!
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
public class Auto { private String make; private String model; private int year; } a) write...
public class Auto { private String make; private String model; private int year; } a) write a default constructor for the Auto Class n) Write a constructor to initialize all instance variables c) write accessor and mutator for make variable d) create an onject name it myAuto with values of Toyota, Camry, and 2016
Create an application (in C++) that stores Inventory records for a retail store. The application should...
Create an application (in C++) that stores Inventory records for a retail store. The application should have an Inventory class with the following properties: InvNumber: A string used to hold an inventory number. Each item in the inventory should have a unique inventory number. Description: A string that holds a brief description of the item. Cost: A decimal value that holds the amount that the retail store paid for the item. Retail: A decimal value that holds the retail price...
Create a class that holds name and address information. Store all the information in character strings...
Create a class that holds name and address information. Store all the information in character strings that are private members of the class. Include a public function that stores the name and address. Also include a public function that displays the name and address. (Call these functions store() and display().)
Language: JavaScript Create a public class called Inverter with a single class method named invert. invert...
Language: JavaScript Create a public class called Inverter with a single class method named invert. invert should accept a Map<String, Integer> and return a Map<Integer, String> with all of the key-value pairs swapped. You can assert that the passed map is not null. Because values are not necessarily unique in a map, normally you would need a way to determine what the right approach is when two keys map to the same value. However, the maps passed to your function...
in JAVA Write a class Store which includes the attributes: store name and sales tax rate....
in JAVA Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn Store class, also code a method returning the...
Java Create a new Drive class. * Create a Menu class. * The menu class will...
Java Create a new Drive class. * Create a Menu class. * The menu class will use the previous 4 classes you created in GCD, LCM, FACTORIAL, DIGITS The Menu will display a menu that give you the option of selecting: 1) Greatest Common Denominator 2) Lowest Common Multiple 3) Factorial 4) Number of Digits in an Integer Enter 1,2,3 or 4: When the User enter the choice, then the correct function/method is called for the class and asks the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT