powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / Массивы простых дробей
2 сообщений из 2, страница 1 из 1
Массивы простых дробей
    #39613063
Iridze
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
У меня есть работающая программа, которая принимает размерности двух массивов и проводит их сложение, вычитание и умножение. Также все парные эл. массива нужно умножить на 3. И надо найти минимальное значение каждого из введенных массивов.
Я реализовала ее для целых и действительных чисел, но я не могу понять как реализовать для простых дробей.

Header.h


Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
#ifndef Array_h
#define Array_h
 
#include <iostream>
 
using namespace std;
 
template<typename T> class arrr 
{
    
    template <typename T>
    friend arrr<T> operator+ (arrr<T> &m1, arrr<T> &m2);
    template <typename T>
    friend arrr<T> operator- (arrr<T> &m1, arrr<T> &m2);
    template <typename T>
    friend arrr<T> operator* (arrr<T> &m1, arrr<T> &m2);
    
 
    friend istream &operator>>(istream &istr, arrr &k)
    {
        for (int i = 0; i<k.n; i++)
            for (int j = 0; j<k.m; j++)
                istr >> k(i, j);
        return(istr);
    }
 
    friend ostream &operator<<(ostream &ostr, arrr &k)
    {
        for (int i = 0; i<k.n; i++)
        {
            for (int j = 0; j<k.m; j++)
                ostr << k(i, j) << "\t";
            ostr << "\n";
        }
        return(ostr);
    }
    private:
    int n, m;
    T **value;
    public:
    T & operator()(int n, int m);
    
    arrr(int no, int mo) {
        n = no;
        m = mo;
        value = new T *[n];
        for (int i = 0; i < n; i++)
            value[i] = new T[m];
    }
 
    arrr()
    {
        n = 0;
        m = 0;
    }
 
    class error {};
    };
 
    template <typename T> arrr<T> operator+(arrr<T>& m1, arrr<T>& m2)
    {
        if (m1.n == m2.n && m1.m == m2.m)
        {
            arrr<T> temp(m1.n, m1.m);
            for (int i = 0; i < m1.n; i++)
                for (int j = 0; j < m1.m; j++)
                    temp(i, j) = m1(i, j) + m2(i, j);
            return(temp);
        }
        else throw arrr<T>::error();
    }
 
    template <typename T> arrr<T> operator-(arrr<T>& m1, arrr<T>& m2)
    {
        if (m1.n == m2.n && m1.m == m2.m) 
        {
            arrr<T> temp(m1.n, m1.m);
            for (int i = 0; i < m1.n; i++)
                for (int j = 0; j < m1.m; j++)
                    temp(i, j) = m1(i, j) - m2(i, j);
            return(temp);
        }
        else throw arrr<T>::error();
    }
 
    template <typename T> arrr<T> operator*(arrr<T>& m1, arrr<T>& m2)
    {
        if (m1.n == m2.m) 
        {
            arrr<T> temp2(m1.n, m1.m);
            for (int i = 0; i < m1.n; i++)
            {
                for (int j = 0; j < m2.m; j++) 
                {
                    temp2(i, j) = 0;
                    for (int k = 0; k < m1.m; k++)
                        temp2(i, j) += m1(i, k) * m2(k, j);
                }
            }
            return(temp2);
        }
        else throw arrr<T>::error();
 
    }
 
 
    template <typename T> T min(arrr<T>& value, int n, int m)
    {
        int i = 0, j = 0;
        T min = value(i, j);
 
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                if (min >= value(i, j))
                {
                    min = value(i, j);
                }
            }
        }
        cout << min << "\t";
    return 0;
    }
 
    
 
template <typename T> T& arrr<T>::operator()(int n, int m)
{
    return (value[n][m]);
}
 
template <typename T> static T parn (arrr<T>& value,int n, int m)
{
    int i, j;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
        {
            int n = value(i, j);
            if (n % 2 == 0)
            {
                value(i, j) *= 3;
 
            }
            cout << value(i, j) << "\t";
        }
        cout << "\n";
    }
 
 
    return 0;
}
 
#endif




6.cpp

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
#include "stdafx.h"
#include <iostream>
#include "Header.h"
 
using namespace std;
 
void PlayINT(int n, int m ,int n1, int m1)
{
    arrr<int> a(n, m);
    arrr<int> b(n1, m1);
    arrr<int> c;
    arrr<int> d;
    arrr<int> z;
 
    cout << "enter matrix A:\n";
    cin >> a;
    cout << "enter matrix B:\n";
    cin >> b;
    cout << "MIN A: ";
    min(a, n, m);
    cout << "\n";
    cout << "MIN B: ";
    min(b, n1, m1);
    cout << "\n";
    try {
        c = a + b;
        cout << "sum of two matrices A and B :\n" << c;
    }
    catch (arrr<int>::error) {
        cout << "error: the sizes of summable matrices must coincide " << endl;
    }
    try {
        d = a - b;
        cout << "subtraction of two matrices A and B:\n" << d;
    }
    catch (arrr<int>::error)
    {
        cout << "error:the sizes of matrices must coincide" << endl;
    }
    try {
        z = a * b;
        cout << "multiplication of two matrices A and B:\n" << z;
    }
    catch (arrr<int>::error)
    {
        cout << "error: the number of columns of the first matrix must coincide with the number of rows of the second matrix" << endl;
    }
    cout << "All items with paired values are increased three times, matrice A:" << endl;
    parn(a, n, m);
    cout << "All items with paired values are increased three times, matrice B:" << endl;
    parn(b, n1, m1);
}
 
void PlayFloat(int n, int m, int n1, int m1)
{
    arrr<float> a(n, m);
    arrr<float> b(n1, m1);
    arrr<float> c;
    arrr<float> d;
    arrr<float> z;
 
    cout << "enter matrix A:\n";
    cin >> a;
    cout << "enter matrix B:\n";
    cin >> b;
    cout << "MIN A: ";
    min(a, n, m);
    cout << "\n";
    cout << "MIN B: ";
    min(b, n1, m1);
    cout << "\n";
    try {
        c = a + b;
        cout << "sum of two matrices A and B :\n" << c;
    }
    catch (arrr<float>::error) {
        cout << "error: the sizes of summable matrices must coincide " << endl;
    }
    try {
        d = a - b;
        cout << "subtraction of two matrices A and B:\n" << d;
    }
    catch (arrr<float>::error)
    {
        cout << "error:the sizes of matrices must coincide" << endl;
    }
    try {
        z = a * b;
        cout << "multiplication of two matrices A and B:\n" << z;
    }
    catch (arrr<float>::error)
    {
        cout << "error: the number of columns of the first matrix must coincide with the number of rows of the second matrix" << endl;
    }
    cout << "All items with paired values are increased three times, matrice A:" << endl;
    parn(a, n, m);
    cout << "All items with paired values are increased three times, matrice B:" << endl;
    parn(b, n1, m1);
}
 
 
int main()
{
    int n, m, n1, m1,ch,y=0;
    cout << "enter number of rows and columns of matrice A: ";
    cin >> m >> n;
    cout << "enter number of rows and columns of matrice B: ";
    cin >> m1 >> n1;
 
    do {
        
        cout << "\n 1.INT";
        cout << "\n 2.FLOAT";
        /*cout << "\n 3.DROBI";*/
        cout << "\n 4.Exit ";
        cout << "\nEnter Your Choice: ";
        cin >> ch;
        switch(ch)
        {
        case 1:PlayINT(n, m, n1, m1);
            break;
        case 2: PlayFloat(n, m, n1, m1);
            break;
        /*case 3: PlayDROBI(n, m, n1, m1);
            break;*/
        case 4:y = 1;
            break;
        }
        
    } while (y != 1);
 
    system("pause");
    return 0;
}




Отдельно от этой программы я делала программу для нахождения суммы, разницы, произведения и деления двух дробей. Теоретически надо как-то совместить две программы.


Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
#include "stdafx.h"
#include <iostream>
 
using namespace std;
 
class drobi{
 
private:
    int chislitel, znamenatel;
 
public:
    drobi(int chisl,int zn)
    {
        chislitel = chisl;
        znamenatel = zn;
    }
    drobi()
    {
        chislitel = 0;
        znamenatel = 0;
    }
    
 
    void set ()
    {
            int NOD = 0;
            if (chislitel>znamenatel) NOD = znamenatel; else NOD = chislitel;
            for (int i = NOD; i>0; i--)
            {
                if ((fmod(chislitel, i) == 0) && (fmod(znamenatel, i) == 0))
                {
                    chislitel = chislitel / i;
                    znamenatel = znamenatel / i;
                }
            }
        
        }
 
    void sett()
    {
        int cell;
        int c=chislitel;
        int z=znamenatel;
        if ((chislitel > znamenatel)&& znamenatel!=1)
        {
            cell = c / z;
            c = c%z;
            cout << "OR";
            cout << '\t' << '\t' << '\t';
            cout << cell << " " << c << "/" << z;
        }
        if (znamenatel > chislitel)
        {
            z = z / c;
            c = c / c;
            cout << "OR";
            cout << '\t' << '\t' << '\t';
            cout << c << "/" << z;
            
        }
         if (znamenatel == 1) {
            cout << "OR";
            cout << '\t' << '\t' << '\t';
            cout << c;
        }
    
        else cout << " ";
    }
    
 
    drobi operator+(drobi dr)
    {
        int ymn;
        if (znamenatel != dr.znamenatel)
        {
            ymn = znamenatel;
            znamenatel = znamenatel*dr.znamenatel;
            chislitel = chislitel*dr.znamenatel;
            dr.chislitel = dr.chislitel*ymn;
            dr.znamenatel = znamenatel;
        }
        int x = chislitel + dr.chislitel;
        cout << "The sum of two fractions: ";
        return drobi(x, znamenatel);
    }
 
    drobi operator-(drobi dr)
    {
        int ymn;
        if (znamenatel != dr.znamenatel)
        {
            ymn = znamenatel;
            znamenatel = znamenatel*dr.znamenatel;
            chislitel = chislitel*dr.znamenatel;
            dr.chislitel = dr.chislitel*ymn;
            dr.znamenatel = znamenatel;
        }
        int x = chislitel - dr.chislitel;
        cout << "Fraction minus the fraction: ";
        return drobi(x, znamenatel);
    }
 
    drobi operator*(drobi dr)
    {
        int x = chislitel*dr.chislitel;
        int y = znamenatel*dr.znamenatel;
        cout << "The product of two fractions: ";
        return drobi(x, y);
    }
 
    drobi operator/(drobi dr)
    {
        int x = chislitel*dr.znamenatel;
        int y = znamenatel*dr.chislitel;
        cout << "The fraction of one fraction in another: ";
        return drobi(x, y);
    }
 
    friend ostream& operator<<(ostream& stream,const drobi& obj)
    {
        stream << obj.chislitel << "/";
        stream << obj.znamenatel << endl;
        return stream;
    }
 
    friend istream& operator>>(istream& stream, drobi& obj)
    {
        stream >> obj.chislitel;
        stream >> obj.znamenatel;
        return stream;
    }
    
 
};
int main()
{   
    drobi a;
    cout << "Enter the numerator and denominator of the first fraction"<<endl;
    cin >> a;
        a.set();
        cout << "Reduction of fractions: "<<a;
        
        a.sett();
        cout << "\n";
        drobi b;
        cout << "Enter the numerator and denominator of the second fraction"<<endl;
        cin >> b;
        b.set();
        cout << "Reduction of fractions: "<<b;
         b.sett();
        cout << "\n";
        drobi c = a + b;
        c.set();
        cout << c << endl;
         c.sett();
        cout << "\n";
        drobi d = a-b;
        d.set();
        cout << d << endl;
         d.sett();
        cout << "\n";
        drobi e = a*b;
        e.set();
        cout << e << endl;
         e.sett();
        cout << "\n";
        drobi f = a/b;
        f.set();
        cout << f << endl;
       f.sett();
        cout << "\n";
 
    system ("pause");
    return 0;
}




Я попыталась совместить их.
Получилось как-то так, но везде в функции PlayDROBI выдает ошибки:
Ошибка C2039 sett: не является членом "arrr<drobi>"
Ошибка (активно) E0135 class "arrr<drobi>" не содержит члена "sett"

Header.h

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
#ifndef Array_h
#define Array_h
 
#include <iostream>
 
using namespace std;
 
class drobi {
 
private:
    int chislitel, znamenatel;
 
public:
    drobi(int chisl, int zn)
    {
        chislitel = chisl;
        znamenatel = zn;
    }
    drobi()
    {
        chislitel = 0;
        znamenatel = 0;
    }
 
 
    void set()
    {
        int NOD = 0;
        if (chislitel>znamenatel) NOD = znamenatel; else NOD = chislitel;
        for (int i = NOD; i>0; i--)
        {
            if ((fmod(chislitel, i) == 0) && (fmod(znamenatel, i) == 0))
            {
                chislitel = chislitel / i;
                znamenatel = znamenatel / i;
            }
        }
 
    }
 
    void sett()
    {
        int cell;
        int c = chislitel;
        int z = znamenatel;
        if ((chislitel > znamenatel) && znamenatel != 1)
        {
            cell = c / z;
            c = c % z;
            cout << "OR";
            cout << '\t' << '\t' << '\t';
            cout << cell << " " << c << "/" << z;
        }
        if (znamenatel > chislitel)
        {
            z = z / c;
            c = c / c;
            cout << "OR";
            cout << '\t' << '\t' << '\t';
            cout << c << "/" << z;
 
        }
        if (znamenatel == 1) {
            cout << "OR";
            cout << '\t' << '\t' << '\t';
            cout << c;
        }
 
        else cout << " ";
    }
 
 
    drobi operator+(drobi dr)
    {
        int ymn;
        if (znamenatel != dr.znamenatel)
        {
            ymn = znamenatel;
            znamenatel = znamenatel * dr.znamenatel;
            chislitel = chislitel * dr.znamenatel;
            dr.chislitel = dr.chislitel*ymn;
            dr.znamenatel = znamenatel;
        }
        int x = chislitel + dr.chislitel;
        cout << "The sum of two fractions: ";
        return drobi(x, znamenatel);
    }
 
    drobi operator-(drobi dr)
    {
        int ymn;
        if (znamenatel != dr.znamenatel)
        {
            ymn = znamenatel;
            znamenatel = znamenatel * dr.znamenatel;
            chislitel = chislitel * dr.znamenatel;
            dr.chislitel = dr.chislitel*ymn;
            dr.znamenatel = znamenatel;
        }
        int x = chislitel - dr.chislitel;
        cout << "Fraction minus the fraction: ";
        return drobi(x, znamenatel);
    }
 
    drobi operator*(drobi dr)
    {
        int x = chislitel * dr.chislitel;
        int y = znamenatel * dr.znamenatel;
        cout << "The product of two fractions: ";
        return drobi(x, y);
    }
 
    friend ostream& operator<<(ostream& stream, const drobi& obj)
    {
        stream << obj.chislitel << "/";
        stream << obj.znamenatel << endl;
        return stream;
    }
 
    friend istream& operator>>(istream& stream, drobi& obj)
    {
        stream >> obj.chislitel;
        stream >> obj.znamenatel;
        return stream;
    }
};
 
template<typename T> class arrr 
{
    
    template <typename T>
    friend arrr<T> operator+ (arrr<T> &m1, arrr<T> &m2);
    template <typename T>
    friend arrr<T> operator- (arrr<T> &m1, arrr<T> &m2);
    template <typename T>
    friend arrr<T> operator* (arrr<T> &m1, arrr<T> &m2);
    
 
    friend istream &operator>>(istream &istr, arrr &k)
    {
        for (int i = 0; i<k.n; i++)
            for (int j = 0; j<k.m; j++)
                istr >> k(i, j);
        return(istr);
    }
 
    friend ostream &operator<<(ostream &ostr, arrr &k)
    {
        for (int i = 0; i<k.n; i++)
        {
            for (int j = 0; j<k.m; j++)
                ostr << k(i, j) << "\t";
            ostr << "\n";
        }
        return(ostr);
    }
    private:
    int n, m;
    T **value;
    public:
        
    T & operator()(int n, int m);
    
    arrr(int no, int mo) {
        n = no;
        m = mo;
        value = new T *[n];
        for (int i = 0; i < n; i++)
            value[i] = new T[m];
    }
 
    arrr()
    {
        n = 0;
        m = 0;
    }
 
    class error {};
    };
 
    template <typename T> arrr<T> operator+(arrr<T>& m1, arrr<T>& m2)
    {
        if (m1.n == m2.n && m1.m == m2.m)
        {
            arrr<T> temp(m1.n, m1.m);
            for (int i = 0; i < m1.n; i++)
                for (int j = 0; j < m1.m; j++)
                    temp(i, j) = m1(i, j) + m2(i, j);
            return(temp);
        }
        else throw arrr<T>::error();
    }
 
    template <typename T> arrr<T> operator-(arrr<T>& m1, arrr<T>& m2)
    {
        if (m1.n == m2.n && m1.m == m2.m) 
        {
            arrr<T> temp(m1.n, m1.m);
            for (int i = 0; i < m1.n; i++)
                for (int j = 0; j < m1.m; j++)
                    temp(i, j) = m1(i, j) - m2(i, j);
            return(temp);
        }
        else throw arrr<T>::error();
    }
 
    template <typename T> arrr<T> operator*(arrr<T>& m1, arrr<T>& m2)
    {
        if (m1.n == m2.m) 
        {
            arrr<T> temp2(m1.n, m1.m);
            for (int i = 0; i < m1.n; i++)
            {
                for (int j = 0; j < m2.m; j++) 
                {
                    temp2(i, j) = 0;
                    for (int k = 0; k < m1.m; k++)
                        temp2(i, j) += m1(i, k) * m2(k, j);
                }
            }
            return(temp2);
        }
        else throw arrr<T>::error();
 
    }
 
 
    template <typename T> T min(arrr<T>& value, int n, int m)
    {
        int i = 0, j = 0;
        T min = value(i, j);
 
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                if (min >= value(i, j))
                {
                    min = value(i, j);
                }
            }
        }
        cout << min << "\t";
    return 0;
    }
 
    
 
template <typename T> T& arrr<T>::operator()(int n, int m)
{
    return (value[n][m]);
}
 
template <typename T> static T parn (arrr<T>& value,int n, int m)
{
    int i, j;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
        {
            int n = value(i, j);
            if (n % 2 == 0)
            {
                value(i, j) *= 3;
 
            }
            cout << value(i, j) << "\t";
        }
        cout << "\n";
    }
 
 
    return 0;
}
 
#endif




6.сpp

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
#include "stdafx.h"
#include <iostream>
#include "Header.h"
 
using namespace std;
 
void PlayINT(int n, int m ,int n1, int m1)
{
    arrr<int> a(n, m);
    arrr<int> b(n1, m1);
    arrr<int> c;
    arrr<int> d;
    arrr<int> z;
 
    cout << "enter matrix A:\n";
    cin >> a;
    cout << "enter matrix B:\n";
    cin >> b;
    cout << "MIN A: ";
    min(a, n, m);
    cout << "\n";
    cout << "MIN B: ";
    min(b, n1, m1);
    cout << "\n";
    try {
        c = a + b;
        cout << "sum of two matrices A and B :\n" << c;
    }
    catch (arrr<int>::error) {
        cout << "error: the sizes of summable matrices must coincide " << endl;
    }
    try {
        d = a - b;
        cout << "subtraction of two matrices A and B:\n" << d;
    }
    catch (arrr<int>::error)
    {
        cout << "error:the sizes of matrices must coincide" << endl;
    }
    try {
        z = a * b;
        cout << "multiplication of two matrices A and B:\n" << z;
    }
    catch (arrr<int>::error)
    {
        cout << "error: the number of columns of the first matrix must coincide with the number of rows of the second matrix" << endl;
    }
    cout << "All items with paired values are increased three times, matrice A:" << endl;
    parn(a, n, m);
    cout << "All items with paired values are increased three times, matrice B:" << endl;
    parn(b, n1, m1);
}
void PlayDROBI(int n, int m, int n1, int m1) {
    arrr<drobi> a(n, m);
    arrr<drobi> b(n1, m1);
    arrr<drobi> c;
    arrr<drobi> d;
    arrr<drobi> z;
 
    cout << "Enter the numerator and denominator of the first fraction" << endl;
    cin >> a;
    a.set();
    cout << "Reduction of fractions: " << a;
    a.sett();
    cout << "\n";
    cout << "Enter the numerator and denominator of the second fraction" << endl;
    cin >> b;
    b.set();
    cout << "Reduction of fractions: " << b;
    b.sett();
    cout << "\n";
 
    cout << "MIN A: ";
    min(a, n, m);
    cout << "\n";
    cout << "MIN B: ";
    min(b, n1, m1);
    cout << "\n";
 
 
    try {
        c = a + b;
        c.set();
        cout << "sum of two matrices A and B :\n" << c;
        c.sett();
        cout << "\n";
    }
    catch (arrr<float>::error) {
        cout << "error: the sizes of summable matrices must coincide " << endl;
    }
    try {
        d = a - b;  
        d.set();
        cout << "subtraction of two matrices A and B:\n" << d;
        d.sett();
        cout << "\n";
    }
    catch (arrr<float>::error)
    {
        cout << "error:the sizes of matrices must coincide" << endl;
    }
    try {
        z = a * b;
        z.set();
        cout << "multiplication of two matrices A and B:\n" << z;
        z.sett();
        cout << "\n";
    }
    catch (arrr<float>::error)
    {
        cout << "error: the number of columns of the first matrix must coincide with the number of rows of the second matrix" << endl;
    }
    cout << "All items with paired values are increased three times, matrice A:" << endl;
    parn(a, n, m);
    cout << "All items with paired values are increased three times, matrice B:" << endl;
    parn(b, n1, m1);
    
}
void PlayFloat(int n, int m, int n1, int m1)
{
    arrr<float> a(n, m);
    arrr<float> b(n1, m1);
    arrr<float> c;
    arrr<float> d;
    arrr<float> z;
 
    cout << "enter matrix A:\n";
    cin >> a;
    cout << "enter matrix B:\n";
    cin >> b;
    cout << "MIN A: ";
    min(a, n, m);
    cout << "\n";
    cout << "MIN B: ";
    min(b, n1, m1);
    cout << "\n";
    try {
        c = a + b;
        cout << "sum of two matrices A and B :\n" << c;
    }
    catch (arrr<float>::error) {
        cout << "error: the sizes of summable matrices must coincide " << endl;
    }
    try {
        d = a - b;
        cout << "subtraction of two matrices A and B:\n" << d;
    }
    catch (arrr<float>::error)
    {
        cout << "error:the sizes of matrices must coincide" << endl;
    }
    try {
        z = a * b;
        cout << "multiplication of two matrices A and B:\n" << z;
    }
    catch (arrr<float>::error)
    {
        cout << "error: the number of columns of the first matrix must coincide with the number of rows of the second matrix" << endl;
    }
    cout << "All items with paired values are increased three times, matrice A:" << endl;
    parn(a, n, m);
    cout << "All items with paired values are increased three times, matrice B:" << endl;
    parn(b, n1, m1);
}
 
 
int main()
{
    int n, m, n1, m1,ch,y=0;
    cout << "enter number of rows and columns of matrice A: ";
    cin >> m >> n;
    cout << "enter number of rows and columns of matrice B: ";
    cin >> m1 >> n1;
 
    do {
        
        cout << "\n 1.INT";
        cout << "\n 2.FLOAT";
        cout << "\n 3.DROBI";
        cout << "\n 4.Exit ";
        cout << "\nEnter Your Choice: ";
        cin >> ch;
        switch(ch)
        {
        case 1:PlayINT(n, m, n1, m1);
            break;
        case 2: PlayFloat(n, m, n1, m1);
            break;
        case 3: PlayDROBI(n, m, n1, m1);
            break;
        case 4:y = 1;
            break;
        }
        
    } while (y != 1);
 
    system("pause");
    return 0;
}




Извините за наглость, но не могли бы вы подсказать как это исправить.
...
Рейтинг: 0 / 0
Массивы простых дробей
    #39613111
Фотография mayton
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Модератор: Постарайтесь не приаттачивать к форуму такие большие простыни кода. Будьте кратки в постановке вопроса.
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / C++ [игнор отключен] [закрыт для гостей] / Массивы простых дробей
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]