Здравствуйте, Stackoverflow. Это действительно мой первый пост на этом форуме. Мне нужно было некоторое руководство по моей программе на С ++, я нахожусь в ситуации, когда я не знаю, с чего начать, чтобы мои обычные и смешанные дроби отображались из файла. Вот что у меня есть для заголовка и файла реализации. Основное внимание уделяется функции iStream in Fraction. cpp, позволяющей отображать смешанные и нормальные дроби из файла. Любая помощь приветствуется!
Вот моя фракция. cpp код
/* USED FOR FUNCTIONS */
#include <iostream>
#include <cmath>
#include <cctype>
#include <cassert>
#include "fraction.h"
using namespace std;
namespace cs10b_fraction
{
ostream& operator << (std::ostream &out, const Fraction printMe)
{
if (printMe.denom == 1)
{
out << printMe.num << endl;
}
else if (printMe.num == 0)
{
out << printMe.num << endl;
}
else if(printMe.denom == -1)
out << printMe.num / printMe.denom << endl;
else if(printMe.num < printMe.denom && printMe.num != 0)
out << printMe.num << "/" << printMe.denom << endl;
else if(abs(printMe.num) > abs(printMe.denom))
out << printMe.num / printMe.denom << "+" << (printMe.num % printMe.denom) << "/" << printMe.denom << endl;
/* else if (abs(printMe.num) > abs(printMe.denom))
out << printMe.num / printMe.denom << endl;
else if (abs(printMe.num) > abs(printMe.denom))
out << printMe.num / printMe.denom << "+" << (printMe.num % printMe.denom) << "/" << printMe.denom << endl; */
return out;
}
istream& operator >> (std::istream &in, Fraction readMe)
{
int temp;
in >> temp;
if (in.peek() == '+')
{
}
else if (in.peek() == '/')
{
}
else
{
}
return in;
}
}
Вот моя фракция.h код
/*USED FOR CLASS WITH FUNCTIONS ETC */
#ifndef FRACTION_H
#define FRACTION_H
#include <iostream>
#include <cmath>
#include <cctype>
#include <cassert>
using namespace std;
namespace cs10b_fraction
{
class Fraction
{
public:
Fraction(int n = 0, int d = 1)
{
num = n;
denom = d;
assert(denom != 0);
Simplify();
}
friend ostream& operator << (std::ostream &out, const Fraction printMe);
friend std::istream& operator >> (std::istream &in, Fraction readMe);
private:
int num;
int denom;
void Simplify();
};
}
#endif