#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
enum Menu { continent_search = 1, hwak, die, wanchi, EXIT };
enum Menu2 { continent_choice = 1, GO_MAIN };
class country
{
public:
string name;
int hwakjin, die, wanchi;
country(string name, int hwakjin, int die, int wanchi) {
this->name = name;
this->hwakjin = hwakjin;
this->die = die;
this->wanchi = wanchi;
}
bool operator <(country& country) {
return this->hwakjin > country.hwakjin;
return this->wanchi > country.wanchi;
return this->die > country.die;
}
};
class Covid
{
private:
country countries[9] = {
country ("Korea", 4,1,1),
country ("China", 8, 3, 4),
country ("Japan", 6,7,8) }; // where errors occur
public:
Covid() {}
int showhwak(void)
{
sort(countries, countries + 3);
for (int i = 0; i < 3; i++)
{
cout << countries[i].name <<"death" <<countries[i].hwakjin << endl;
}
return 0;
}
void showTitle()
{
cout << "Current status of COVID-19 confirmed patients\n";
}
void showMenu()
{
cout << "==================\n";
cout << "1. Continental search\n";
cout << "2. Number of confirmed cases\n";
cout <<"3. Death toll\n";
cout << "4. Completely cured embroidery\n";
cout <<"5. End\n";
cout << "==================\n";
}
void showcontinentmenu()
{
cout << "==================\n";
cout << "1. Asia\n";
cout <<"2. Africa\n";
cout << "3. Mainly\n";
}
void continent()
{
while (true) {
showcontinentmenu();
int menuNum = inputMenu();
switch (menuNum) {
case continent_choice:
asia();
break;
case GO_MAIN:
return; break;
default:
break;
}
}
}
int inputMenu() {
int menuNum = -1;
cout << "Input>>";
cin >> menuNum;
return menuNum;
}
void _exit() {
exit(0);
}
void asia()
{
string name;
int temp;
cout << "Enter Asian country:\n";
cin >> name;
for (int i = 0; i < 3; i++) {
if (name == countries[i].name)
i = temp;
}
cout << countries[temp].Name < < "dead" < < countries [temp].Hwakjin < < "hwakjjinja" < < countries [temp].wanchi << endl;
}
void showsamang()
{
}
void showwanchi()
{
}
void showcountry()
{
}
void initialize()
{
showTitle();
while (true) {
showMenu();
int menuNum = inputMenu();
switch (menuNum)
{
case continent_search:
continent();
break;
case hwak:
showhwak();
break;
case EXIT:
_exit();
break;
default:
break;
}
}
}
};
int main()
{
Covid covid = Covid();
covid.initialize();
}
In the part where the error occurs, if you erase 9 in [] of the country counties [9], the error occurs as an incomplete format If you write 9, No instance of constructor matching C++ argument list. What's wrong with this error? ㅠ<
c++ visual-studio
country countries[9] = {
Country, ("Korea", 4, 1, 1)
Country, ("China", 3, 3 and 4)
Country ("Japan", 6, 7, 8)} ;
The countries
of the code is an array of nine elements.
Because you assigned values to a variable for three elements, six elements are created through the default constructor.
However, the default constructor is deleted because you defined the country(string name, inthwakjin, int die, int wanchi) constructor in the
country
class.
Therefore, the countries
array cannot be created because it does not have a default constructor for country
.
You can fix the problem by setting the default values for the parameters as shown below.
country(string name = {}, int hwakjin = 0, int die = 0, int wanchi = 0)
© 2024 OneMinuteCode. All rights reserved.