diff --git a/Bai thuc hanh so 7/FIRSTFILE.txt b/Bai thuc hanh so 7/FIRSTFILE.txt new file mode 100644 index 0000000..b48470d --- /dev/null +++ b/Bai thuc hanh so 7/FIRSTFILE.txt @@ -0,0 +1,10 @@ +Probleam name: exp1 +Maximize +obj: x1 + 2 x2 + 3 x3 + x4 +Subject To + c1: x2 - 3.5 x4 = 0 +Bounds + 0 <= x1 <= 40 +General + x4 +End \ No newline at end of file diff --git a/Bai thuc hanh so 7/MATRIX.txt b/Bai thuc hanh so 7/MATRIX.txt new file mode 100644 index 0000000..3823d53 --- /dev/null +++ b/Bai thuc hanh so 7/MATRIX.txt @@ -0,0 +1,4 @@ +3 4 +4 5 1 24 +54 654 534 33 +11 213 43 1 diff --git a/Bai thuc hanh so 7/bai1.cpp b/Bai thuc hanh so 7/bai1.cpp index 99b8c2e..d701e56 100644 --- a/Bai thuc hanh so 7/bai1.cpp +++ b/Bai thuc hanh so 7/bai1.cpp @@ -3,12 +3,32 @@ using namespace std; -int main(){ - ifstream InputFile("FIRSTFILE.txt"); +void writeFile(string filename){ + ofstream file(filename, ios::out); + file << "Probleam name: exp1" << endl; + file << "Maximize" << endl; + file << "obj:\t\t\t x1 + 2 x2 + 3 x3 + x4" << endl; + file << "Subject To" << endl; + file << "\t c1: x2 - 3.5 x4 = 0" << endl; + file << "Bounds" << endl; + file << "\t 0 <= x1 <= 40" << endl; + file << "General" << endl; + file << "\t x4" << endl; + file << "End"; + file.close(); +} + +void readFile(string filename){ + ifstream file(filename); string s; - while (getline(InputFile,s)){ + while (getline(file,s)){ cout << s << endl; } - InputFile.close(); + file.close(); +} + +int main(){ + writeFile("FIRSTFILE.txt"); + readFile("FIRSTFILE.txt"); return 0; } diff --git a/Bai thuc hanh so 7/bai3.cpp b/Bai thuc hanh so 7/bai3.cpp index 6151976..d6d02a6 100644 --- a/Bai thuc hanh so 7/bai3.cpp +++ b/Bai thuc hanh so 7/bai3.cpp @@ -3,34 +3,42 @@ using namespace std; -int main(){ +void create(string filename){ int n,m; cout << "Nhap n: "; cin >> n; cout << "Nhap m: "; cin >> m; - ofstream ofile; - ofile.open("MATRIX.txt"); - ofile << n << " " << m << endl; + ofstream file("MATRIX.txt",ios::out); + file << n << " " << m << endl; for (int i=0;i> temp; - ofile << temp << " "; + file << temp << " "; } - ofile << endl; + file << endl; } - ofile.close(); + file.close(); +} - int a[1000][1000]; - ifstream ifile("MATRIX.txt"); - ifile >> n >> m; +void read(string filename, int **&a, int &n, int &m){ + ifstream file(filename); + file >> n >> m; + a = new int*[n]; + for (int i=0;i> a[i][j]; + file >> a[i][j]; } } + file.close(); +} + +void print(int **a, int n, int m){ cout << "Mang hai chieu da nhap la: " << endl; for (int i=0;i