Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- class Dathuc{
- private:
- float Heso[100];
- int n;
- public:
- void nhap(){
- cin>>n;
- for(int i=n;i>=0;i--){
- cin>>Heso[i];
- }
- }
- void hienthi(){
- for(int i=n;i>=0;i--){
- if(i==0){
- cout<<Heso[i];
- }
- else{
- cout<<Heso[i]<<"*x^"<<i<<"+";
- }
- }
- }
- void docFile(){
- ifstream f;
- f.open("Dathuc.in");
- f>>n;
- for(int i=n;i>=0;i--){
- f>>Heso[i];
- }
- for(int i=n;i>=0;i--){
- if(i==0){
- cout<<Heso[i];
- }
- else{
- cout<<Heso[i]<<"*x^"<<i<<"+";
- }
- }
- f.close();
- }
- void ghiFile(){
- ofstream f;
- f.open("Dathuc.out");
- f<<n<<endl;
- for(int i=n;i>=0;i--){
- if(i==0){
- f<<Heso[i];
- }
- else{
- f<<Heso[i]<<"*x^"<<i<<"+";
- }
- }
- f.close();
- }
- Dathuc Tongdathuc(Dathuc a,Dathuc b){
- if(a.n>=b.n){
- Tongdathuc.n=a.n;
- }
- else{
- Tongdathuc.n=b.n;
- }
- for(int i=Tongdathuc.n;i>=0;i--){
- if(i<=a.n&&i<=b.n){
- Tongdathuc.Heso[i]=a.Heso[i]+b.Heso[i];
- }
- else if(i<=a.n&&i>b.n){
- Tongdathuc.Heso[i]=a.Heso[i];
- }
- else if(i<=b.n&&i>a.n){
- Tongdathuc.Heso[i]=b.Heso[i];
- }
- }
- return Tongdathuc.Heso;
- }
- };
- int main(){
- Dathuc a,b;
- a.nhap();
- a.hienthi();
- b.nhap();
- b.hienthi();
- Dathuc c=a.Tongdathuc(a,b);
- c.hienthi();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement