class Shape
{
public:
virtual void draw() const {cout<<"draw shape"<<endl;}
};
class Point : public Shape
{
public:
Point( int a= 0, int b = 0 ) {x=a; y=b;} // default constructor
int getx() const {return x;}
int gety() const {return y;}
virtual void draw() const {cout<<"draw point("<<x<<","<<y<<")\n";}
private:
int x, y; // x and y coordinates of Point
};
class Circle : public Point
{
public: // default constructor
Circle( double r = 0.0, int x = 0, int …Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <string>
using namespace std;
int main()
{
char option='0';
do
{
cin >> option;
switch (option)
{
case '1':
cout << "testing 1\n";
break;
case '2':
cout << "testing 2\n";
break;
case '3':
cout << "Thank you, Have a nice day.\n";
break;
default:
cout << "Invalid option, Please enter option (1-3).";
}
}while (option != 3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么while循环是无限的.当我键入时3,它应该打印出来Thank you, Have a nice day.并退出循环while (option != 3).但是,似乎while循环不起作用.