Наследование(исправьте синтаксические ошибки)
Добавлено: 27 окт 2010, 02:47
Помогите исправить ошибки:
class ProperFraction: public FloatFraction{
error C2504: 'FloatFraction' : base class undefined
ProperFloatFraction(int n, int d){
set(n, d);
}
warning C4183: 'ProperFloatFraction': missing return type; assumed to be a member function returning 'int'
#include <stdafx.h>
fatal error C1075: end of file found before the left brace '{' at 'FloatFractionV3.cpp(5)' was matched
class ProperFraction: public FloatFraction{
error C2504: 'FloatFraction' : base class undefined
ProperFloatFraction(int n, int d){
set(n, d);
}
warning C4183: 'ProperFloatFraction': missing return type; assumed to be a member function returning 'int'
#include <stdafx.h>
fatal error C1075: end of file found before the left brace '{' at 'FloatFractionV3.cpp(5)' was matched
Код: Выделить всё
#include <stdafx.h>
#include <conio.h>
#include "Fraction.h"
using namespace std;
class FloatFraction : public Fraction {
public:
FloatFraction(){
set(0, 1);
}
FloatFraction(int n, int d){
set(n, d);
}
FloatFraction(int n){
set(n,1);
}
FloatFraction(const Fraction& src){
set(src.get_num(),src.get_den());
}
double get_float(){
return static_cast<double>(get_num())/get_den();
};
class ProperFraction: public FloatFraction{
public:
ProperFraction(){
set(0, 1);
}
ProperFloatFraction(int n, int d){
set(n, d);
}
ProperFraction(int n){
set(n,1);
}
ProperFraction(const Fraction& src){
set(src.get_num(),src.get_den());
}
double get_float(){
return static_cast<double>(get_num())/get_den();
}
void pr_proper(ostream& os){
if(get_whole()!=0)
os << get_whole() << " ";
os << get_num << "/" << get_den();
}
int get_whole(){
int n =get_num();
return n/get_den();
}
int get_num(){
int n = get_num();
return n%get_den();
}
};
int main() {
ProperFraction f1(1,2),f2(5,6),f3;
cout << "Value of f3 is " << f3.pr_proper(cout) << endl;
cout << "Float value of is " << f3.get_float() << endl;
return 0;
}