This repository was archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
af60db9
commit 1edf4f0
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,54 @@ | ||
#include <iostream> | ||
using namespace std; | ||
struct DaThuc | ||
{ | ||
float a[100]; | ||
int n; | ||
}; | ||
typedef struct DaThuc DATHUC; | ||
|
||
void Nhap(DATHUC &); | ||
void Xuat(DATHUC); | ||
DATHUC operator+(DATHUC, DATHUC); | ||
|
||
int main() | ||
{ | ||
DATHUC P; | ||
Nhap(P); | ||
|
||
DATHUC Q; | ||
Nhap(Q); | ||
|
||
DATHUC R = P + Q; | ||
Xuat(R); | ||
|
||
return 0; | ||
} | ||
|
||
void Nhap(DaThuc &P) | ||
{ | ||
cout << "Nhap bac da thuc: "; | ||
cin >> P.n; | ||
for (int i = 0; i <= P.n; i++) | ||
{ | ||
cout << "Nhap he so a[" << i << "]: "; | ||
cin >> P.a[i]; | ||
} | ||
} | ||
|
||
void Xuat(DATHUC P) | ||
{ | ||
cout << "\nDa thuc: "; | ||
for (int i = 0; i <= P.n; i++) | ||
cout << P.a[i] << "x^" << i << " + "; | ||
cout << "\b\b\b "; | ||
} | ||
|
||
DATHUC operator+(DATHUC P, DATHUC Q) | ||
{ | ||
DATHUC temp; | ||
temp.n = (P.n > Q.n) ? P.n : Q.n; | ||
for (int i = 0; i <= temp.n; i++) | ||
temp.a[i] = P.a[i] + Q.a[i]; | ||
return temp; | ||
} |