Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 16.05.2011, 12:31   #1
lodos
Пользователь
 
Регистрация: 06.05.2011
Сообщений: 39
По умолчанию C++ Builder

Нужна помощь в визуальном оформлении, т.е. кнопочки, но не как в каркуляторе, а как в каком-нибудь электронном учебнике. Кто знает подскажите пожалуйста, или наведите на мысль. Заранее спасибо.
Первая часть кода
Код:
using namespace std;
 
class fraction
{
public: 
        fraction();
        fraction(int,int);
        fraction(int);
        fraction& operator +(fraction&);
        fraction& operator *(fraction&);
        fraction& operator /(fraction&);
        fraction& operator -(fraction&);
        friend ostream& operator<<(ostream&, const fraction&);
        friend istream& operator>>(istream&, fraction&);
        bool operator !=(fraction&);
        bool operator >(fraction&);
        bool operator <(fraction&);
        bool operator ==(fraction&);
        fraction& abs();
        int get_numerator();
        int get_denominator();
        int NOD(fraction&);
        static int NOD(const int, const int);
        fraction& reduce();
        ~fraction(){};
private:
        int numerator;
        int denominator;
};
 
int fraction::get_denominator()
{
        return this->denominator;
}
 
int fraction::get_numerator()
{
        return this->numerator;
}
 
bool fraction::operator !=(fraction &x)
{
        return !((*this)==x);
}
 
bool fraction::operator >(fraction &x)
{
        return ((double)this->numerator/this->denominator>(double)x.numerator/x.denominator);
}
 
bool fraction::operator <(fraction &x)
{
        return ((*this)!=x)? !((*this)>x) : false;
}
 
 
bool fraction::operator ==(fraction &x)
{       
        return (this->numerator==x.numerator && this->denominator==x.denominator);
}
 
 
fraction& fraction::abs()
{
        fraction* x=new fraction(*this);
        if (x->numerator<0) 
        {
                x->numerator*=-1;
        }
        if (x->denominator<0)
        {
                x->denominator*=-1;
        }
        return *x;
}
 
fraction::fraction()
{
        numerator=0; denominator=1;
}
 
fraction::fraction(int x, int y)
{
        if (!y)
lodos вне форума Ответить с цитированием
Старый 16.05.2011, 12:32   #2
lodos
Пользователь
 
Регистрация: 06.05.2011
Сообщений: 39
По умолчанию

Вторая часть кода
Код:
{
                denominator=1;
        }
        else
        {
                numerator=x; 
                denominator=y;
        }
}
 
fraction::fraction(int x)
{
        numerator=x; denominator=1;
}
 
fraction& fraction::operator *(fraction& x)
{
        return *(new fraction(this->numerator*x.numerator,this->denominator*x.denominator));
}
 
fraction& fraction::operator +(fraction& x)
{
        return *(new fraction(this->numerator*x.denominator/NOD(x)
                +x.numerator*this->denominator/NOD(x),
                this->denominator*x.denominator/NOD(x)));
}
 
fraction& fraction::operator -(fraction& x)
{
        return *(new fraction((*this)+x*(*(new fraction(-1)))));
}
 
fraction& fraction::operator /(fraction& x)
{
        return *(new fraction(this->numerator*x.denominator,this->denominator*x.numerator));
}
 
int fraction::NOD(fraction& x)
{
        this->reduce(); x.reduce();
        int c, a=this->denominator, b=x.denominator;
        while (b) 
        {
                c = a%b;
                a = b;
                b = c;        
        }
        return a;
}
                
int fraction::NOD(const int x, const int y)
{
        int c, a=x, b=y;
        while (b) 
        {
                c = a%b;
                a = b;
                b = c;        
        }
        return a;
}
 
fraction& fraction::reduce()
{
        int x=NOD(denominator,numerator);
        this->denominator/=x;
        this->numerator/=x;
        return *this;
}
 
ostream& operator<<(ostream& os, fraction& f)
{
        f.reduce();
        int numerator=f.get_numerator(), denominator=f.get_denominator();
        if (numerator!=0)
        {
                if (denominator==1) 
                {
                        os<<numerator;
                }
                else
                {
                        if (denominator==-1)
                        {
                                os<<-numerator;
                        }
                        else
                        {
                                if (denominator<0)
                                {
                                        os<<-numerator<<'/'<<-denominator;
                                }
                                else
                                {
                                        os<<numerator<<'/'<<denominator;
                                }
                        }
                }
        }
        else
        {
                os<<0;
        }
        return os;
}
 
istream& operator>>(istream& is, fraction& f)
{
        char delim;
        is>>f.numerator>>delim>>f.denominator;
        return is;
}
 
int _tmain(int argc, _TCHAR* argv[])
{
        fraction x, y, result;
        char operand;
        do
        {
                cout<<"Input fractions: ";
                cin>>x>>operand>>y;
                switch(operand)
                {
                case '+':
                        result=x+y;
                        break;
                case '-':
                        result=x-y;
                        break;
                case '*':
                        result=x*y;
                        break;
                case '/':
                        result=x/y;
                        break;
                default:
                        cout<<"Incorrect operand!";
                }
                cout<<"="<<result<<endl;
                cout<<"Press esc to exit.."<<endl;
        }
        while (_getch()!=27);
        return 0;
}
извените за много постов. Просто в одной теме все не влезло.
lodos вне форума Ответить с цитированием
Старый 16.05.2011, 18:52   #3
lodos
Пользователь
 
Регистрация: 06.05.2011
Сообщений: 39
По умолчанию

люди откликнитесь хоть ктото плиз...

Последний раз редактировалось lodos; 16.05.2011 в 20:04.
lodos вне форума Ответить с цитированием
Старый 16.05.2011, 20:20   #4
lodos
Пользователь
 
Регистрация: 06.05.2011
Сообщений: 39
По умолчанию

мне нужна помощь по созданию визуального оформлени.
lodos вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
CodeGear C++ Builder 2007 Lite не может откомпилировать исходники C++ Builder 6 Ecosasha C++ Builder 2 22.11.2013 15:02
C++ Builder petro_alksv C++ Builder 0 16.05.2011 00:45
Синтаксис Delphi Builder --> C++ Builder KingBelt C++ Builder 2 28.11.2010 16:25
Перенести код из C++ Builder 5 в C++ Builder 2009 Kreadlling C++ Builder 2 13.09.2009 14:00
Builder 6.0 prankish_cat Общие вопросы C/C++ 0 01.02.2009 16:45