It's been some time since I last wrote code, but I'm trying to dust off the few skills I had gained while studying. For now, I'm just trying to implement solutions to statements/questions I see online.
For this I'm trying to build an allergy class that will store information (category, name, symptoms) provided by user input. I started by just taking string input for each parameter, but in the real world, people may have multiple symptoms. For that, i want to create a list parameter for symptoms instead of a single string. Here are my files:
Allergy.hpp:
#ifndef Allergy_hpp #define Allergy_hpp #include <iostream> #include <string> #include <list> using namespace std; class Allergy { public: Allergy(); Allergy(string, string, list <string>); ~Allergy(); //getters string getCategory() const; string getName() const; list <string> getSymptom() const; private: string newCategory; string newName; list <string> newSymptom; }; #endif /* Allergy_hpp */ Allergy.cpp:
#include "Allergy.hpp" Allergy::Allergy(string name, string category, list <string> symptom){ newName = name; newCategory = category; newSymptom = symptom; } Allergy::~Allergy(){ } //getters string Allergy::getName() const{ return newName; } string Allergy::getCategory() const{ return newCategory; } list Allergy::getSymptom() const{ return newSymptom; } main.cpp:
#include <iostream> #include <string> #include "Allergy.hpp" using namespace std; int main() { string name; string category; string symptom; cout << "Enter allergy name: "; getline(cin, name); cout << "Enter allergy category: "; getline(cin, category); cout << "Enter allergy symptom: "; getline(cin, symptom); Allergy Allergy_1(name, category, symptom); cout << endl << "Allergy Name: " << Allergy_1.getName() << endl << "Allergy Category: " << Allergy_1.getCategory() << endl << "Allergy Symptom: " << Allergy_1.getSymptom() << endl; return 0; } I haven't made it to the implementation in main.cpp. For now I'm stuck creating a getter for the list within Allergy.cpp. Any guidance is greatly appreciated!!!