0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【C++】クラスの練習

Posted at

【C++】クラスの練習

クラス使う練習で、特徴を入力すると答えが出てくるプログラムを作っている最中です。。。
オブジェクト指向まだ勉強中で理解できていない段階ですが一旦作りかけ載せました。(※全然できていないので何も参考にはなりません。)

#include <iostream>
#include <string>

using namespace std;

class Fruit {
   public:
    void answer();
};

class Apple : public Fruit {
   public:
    void apple();
};

class Mango : public Fruit {
   public:
    void mango();
};

class Peach : public Fruit {
   public:
    void peach();
};

void Apple::apple() { cout << "りんご" << endl; }

void Mango::mango() { cout << "マンゴー" << endl; }

void Peach::peach() { cout << "もも" << endl; }

int main() {
    string future;
    do {
        cout << "フルーツの特徴を入力して下さい :";
        cin >> future;

        Apple a;
        Mango b;
        Peach c;

        if (future == "red") {
            a.apple();
        } else if (future == "orange") {
            b.mango();
        } else if (future == "pink") {
            c.peach();
        } else {
            cout << "再度入力して下さい" << endl;
        }
    } while (future != "red" && future != "orange" && future != "pink");
}

難しい…。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?