1

I tried to write a program for a project which imitates the scene from professor oak's lab in kanto.My issue is with the Gender display option. I know that I have to overload the operator I just don't know how to overload << operator.

I would like to know the exact piece of code required as I really cannot figure out the solution to the issue I have with the help of the question suggested. String concatenation is all I can do with operator overloading so I need you to be patient with me.

I tried using getline to get the data and display it but did not work. I tried developing a different function for it but did not have any luck as to what to do.

     You will need most of the code to see the issue so I'm posting all of it.
#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
using namespace std;
class trainer
{
    public:
    int gender(int choice)
   {
    if (choice=='1')
    cout<<"boy";
    else
    cout<<"girl";
    } 
char name[20];
int pokeballs;
int potions;
    string starter;
    int first_pokemon;
};
trainer a;
void gender()
{
    int choice;
    cout<<"\nWelcome to the world of Pokemon!\nI'm Professor       Oak.\nPocket Monsters, or Pokemon, are mysterious creatures with special abilities.\nWe pet them, feed them, or even battle alongside them.\nAs for myself,I study Pokemon.\nAnyway,Are you a boy or girl?";
    cin>>choice;
    /*This needs a lot of work.Original piece of code:
    cout<<"\nWelcome to the world of Pokemon!\nAre you a boy?or a girl?"<<endl;
    cin>>a.starter;*/
}
void name()
{
    char choice;
    cout<<"\nTell me your name, Trainer!"<<endl;;
    cin>>a.name;
    cout<<a.name;
    cout<<",tell me, are you ready to be a pokemon master?Here we go!";
}
void starter()
{
    int choice,starter;
cout<<"\n Choose your starter!";
cout<<"\n1 Charmander \n2 Squirtle \n3 Bulbasaur\n"<<endl;//I should make this an input by the player themselves.takes the burden off.
cin>>choice;
switch(choice)
{
    case 1:
        cout<<"\n Charmander:\n Fire type \tAttack based pokemon.\n Good choice!";
        a.first_pokemon='1';
        break;
    case 2:
        cout<<"\n Squirtle:\n Water type \tDefense based pokemon.\n Good choice!";
        a.first_pokemon='2';
        break;
    case 3:
        cout<<"\n Bulbasaur:\n Grass type \tAgility based pokemon.\n Good choice!";
        a.first_pokemon='3';
        break;
}
cout<<"What will you pokemon be called then?";
cin>>a.starter;
cout<<"\nAnyways, here are five PokeBalls to get you going.\n Have fun!"<<endl;
a.pokeballs='5';
}
void license()
{
    cout<<"Before I forget, this is your Trainer License!"<<endl;
    cout<<setw(25)<<"\nName:\t"<<a.name;
    cout<<setw(25)<<"\nAge:\t"<<"10";
    cout<<setw(25)<<"\nRegion:\t"<<"Kanto";
    cout<<setw(25)<<"\nGender:\t"<<a.gender;
    cout<<setw(25)<<"\nStarter:"<<a.starter;
    cout<<"\n\t\tAPPROVED BY PROF.OAK";
}
int main()
{
    cout<<setw(25)<<"OAK'S LAB:"<<endl;
    cout<<"\a";
    gender();
    name();
    starter();
    license();
    return 0;
}

I want the output to say the gender out in words (boy or girl) based on their choice (1 or 2).

Seto Kaiba
  • 19
  • 5

0 Answers0