-
04-10-2015, 07:43 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
viết hàm đọc viết số phức ra file ??? Mình viết nó bị lỗi mọi người xem dùm mình với :((
#include <iostream>
#include <fstream>
using namespace std;
class Complex{
private:
int _im;
int _real;
public:
Complex(){
this -> _im = 0;
this -> _real = 0;
}
Complex(int im, int _ireal){
this -> _im = im;
this -> _real = _ireal;
}
friend istream & operator >> (istream &is, Complex &sp){
is >> sp._real;
is >> sp._im;
return is;
}
friend ostream & operator << (ostream &os, Complex &sp){
os << sp._real;
os << sp._im;
return os;
}
Complex operator / (const Complex &sp){
return Complex(((_real*sp._real+_im*sp._im)/(sp._real*sp._real+sp._im*sp._im)),((_im*sp._real-_real*sp._im)/(sp._real*sp._real+sp._im*sp._im)));
}
Complex operator - (const Complex &sp){
return Complex((_real - sp._real),(_im - sp._im));
}
Complex operator + (const Complex &sp){
return Complex((_real + sp._real),(_im + sp._im));
}
int readComplex(char* filename, Complex c[], int &n){
fstream f ("input.txt", ios :: in);
if(!f){
cout << "File khong mo duoc" << endl;
return 0;
}
f >> n;
int i = 0;
while(!f.eof()){
f >> c[i];
i++;
}
f.close();
return 1;
}
int writeComplex(char *filename, Complex c[], int &n){
fstream f("output.txt", ios :: app);
if(!f){
cout << "File khong mo duoc" << endl;
return 0;
}
for(int i = 0; i < n; i++){
f << c[i] << " ";
}
f.close();
return 1;
}
};
int main(int argc, char* argv[]){
Complex c[100];
Complex f;
int n;
cout << "Nhap n: ";
cin >> n;
f.readComplex(argv[2], c, n);
f = (c[0] - c[1]);
f = (c[0] - c[1])/c[2];
f.writeComplex(argv[2], c, n);
}View more random threads:
- Gửi 1 email mạo danh trong lập trình C#
- tính tổng
- Tìm Hiểu Biểu Thức Qui Tắc trong lập trình C# Qua Ví Dụ
- Đóng gói phần mềm + SQL 2k5 + .Net!! Với Setup Factory 9.0. Have fun!!
- Chương trình tạo hiệu ứng tuyết rơi với lập trình C#
- Địa Điểm Cài Đặt Phần Mềm Cad Uy Tín Q. 6 Tận Nhà
- Canh vị trí cho các thành phần trong CSS
- Mã hóa chuỗi bằng các kiểu mã hóa ký tự trong lập trình C#
- 21 Important FAQ questions for WPF and SilverLight
- Thêm điều kiểm vào form lúc thực thi trong lập trình C#
Ngọc Bích xanh bản chất thuộc dòng đá đá hoa (jade). Và cẩm thạch là tên gọi chung của ngọc bích. Vì thực chất chúng thuộc dòng đá đa khoáng được hình thành từ chất Silicat dưới dạng dioxy. Ngọc bích...
Chia sẻ Vòng tay ngọc bích xanh là...