-
04-10-2015, 07:46 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:
- Xây dựng Login Control trong lập trình C#
- Cách sử dụng và tạo snippets trong lập trình C#?
- So sánh ListView với GridView, DataList và Repeater
- Chương trình kích hoạt chức năng Hibernate của Windows trong lập trình C#
- Sử dụng biến Nullable trong lập trình C#
- ai giúp cái code từ điển bằng mảng băm và DSLK kép với . mới biết xơ xơ à . chỉ biết làm cái DLSK đơn . ai giúp với
- Mới hoàn thành code valid email account. Share cho anh em tham khảo lấy thanks.
- Những phương thuốc trắng đa từ bài bác thuốc dân phòng
- RoleProvider MVC3 (Login Phân Quyền)
- địa ๑ chỉ ✦ ip ✤ có ❣ thật ❉ sự ✚ ảnh ۩ hưởng ۩ tới ❦ thứ ✪ hạng ✦ website ❥ ?
Với sự đa dạng và phong phú về mẫu mã và giá cả, choxeonline.vn hứa hẹn sẽ là địa chỉ tin cậy cho những ai đang tìm kiếm chiếc xe ô tô ưng ý. Từ những mẫu xe hạng sang đến những chiếc xe gia đình...
Khám Phá Đa Dạng Sản Phẩm Xe Ô Tô...