我在编写程序时遇到问题,因为它一直告诉我我的所有转换函数都有未定义的引用。
我正在寻找有关我在代码中可能忽略的内容的建议。此外,我正在寻找有关如何设置我的实施部分以及设置转化的建议。
的main.cpp
#include "MetricConverter.h"
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
void convert_kg_lbs();
void convert_km_mi();
void convert_liters_quarts();
void convert_celsius_fahrenheit();
int main()
{
char selection;
do
{
// display menu
system("cls");
cout << "Welcome to the Metric Converter!"
<< "1) Kg to lbs " << endl
<< "2) KM to Mi " << endl
<< "3) liters to quarts " << endl
<< "4) celsius to fahrenheit: " << endl
<< "5) Exit" << endl;
cout << "Enter Selection: " << endl;
cin >> selection;
// switch choice
switch (selection)
{
case '1': convert_kg_lbs(); break;
case '2': convert_km_mi(); break;
case '3': convert_liters_quarts(); break;
case '4': convert_celsius_fahrenheit(); break;
case '5': break;
default:
cout << "Invalid Choice! " << endl;
system("PAUSE");
}
} while (selection != '5');
return 0;
}
void convert_kg_lbs()
{
// get input (kg)
double KG;
system("cls");
cout << "--[Convert KG to pounds]";
cout << "Enter kilograms: ";
cin >> KG;
printf("\n%.2f KG = %.2f lbs\n\n", KG, MetricConverter::KG_lbs(KG));
system("PAUSE");
}
void convert_km_mi()
{
// get input(km)
double KM;
system("cls");
cout << "Convert KM to Miles";
cout << "Enter KM: ";
cin >> KM;
printf("\n%.2f KM = %.2f miles\n\n", KM, MetricConverter::KM_miles(KM));
system("PAUSE");
}
void convert_liters_quarts()
{
// get input (liters)
double liters;
system("cls");
cout << "Convert Liters to Quarts";
cout << "Enter Liters: ";
cin >> liters;
printf("\n%.2f liters = %.2f quarts\n\n", liters, MetricConverter::Liters_quart(liters));
system("PAUSE");
}
void convert_celsius_fahrenheit()
{
// get input (celsius)
double celsius;
system("cls");
cout << "Convert celsius to fahrenheit";
cout << "Enter celsius: ";
cin >> celsius;
printf("\n%.2f celsius = %.2f fahrenheitn\n", celsius, MetricConverter::Celsius_fahrenheit(celsius));
system("PAUSE");
}
MetricConverter.h
#ifndef METRICCONVERTER_H
#define METRICCONVERTER_H
class MetricConverter
{
public:
MetricConverter();
static double KG_lbs(double KG);
static double KM_miles(double);
static double Liters_quart(double);
static double Celsius_fahrenheit(double);
};
#endif // METRICCONVERTER_H
实施MetricConverter.cpp
#include "MetricConverter.h"
MetricConverter::MetricConverter()
{
}
double KG_lbs(double KG)
{
}
double KM_miles(double KM)
{
}
double Liters_quart(double Liters)
{
}
double Celsius_fahrenheit(double Celsius)
{
}
答案 0 :(得分:0)
更改这些:
static double KG_lbs(double KG)
{
}
到
static double MetricConverter::KG_lbs(double KG)
{}