Fairly new to classes, so sorry in advance. I need to store fruit names e.g. apple & banana in an array, but I'm not sure where/how to set these strings in an array. fruitName should be the array and its initialize in constructor is "". I need to set fruit names in an array but how do I do that?
//store.h
#ifndef STORE_H
#define STORE_H
#include <iostream>
using namespace std;
class fruit
{
private:
string fruitName; //Name of Fruit
double unit; //Unit Price of Fruit
int quantity; //Quantity of Fruit
public:
fruit(); // Default Constructor
fruit(string, int, double);
I edited my program and got it in an array, however, I don't know how I can access it from there. The array is private and I don't know how to access each element. For each fruit, I need to set a Unit Price.
// In store.cpp file
//Store fruit type in array
const string fruit::fruitName[100] =
{"Apple", "Banana", "Grape", "Orange", "Pear", "Exit"};
//Set unit price to fruit type
void fruit::setUnit()
{
fruitName[0] = 0.99; // Trying to set Apple to 0.99
}