Skip to content

Commit

Permalink
Perfected some code
Browse files Browse the repository at this point in the history
  • Loading branch information
lamhoangtung committed Aug 6, 2018
1 parent 144adef commit d7e9852
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
10 changes: 10 additions & 0 deletions Bai thuc hanh so 7/FIRSTFILE.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Bai thuc hanh so 7/MATRIX.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 4
4 5 1 24
54 654 534 33
11 213 43 1
28 changes: 24 additions & 4 deletions Bai thuc hanh so 7/bai1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
37 changes: 26 additions & 11 deletions Bai thuc hanh so 7/bai3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,55 @@

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<n;i++){
for (int j=0;j<m;j++){
cout << "Nhap a[" << i+1 << "," << j+1 << "]: ";
int temp;
cin >> 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<n;i++){
a[i] = new int [m];
}
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
ifile >> 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<n;i++){
for (int j=0;j<m;j++){
cout << a[i][j] << " ";
}
cout << endl;
}
}

int main(){
int n,m,**a;
create("MATRIX.txt");
read("MATRIX.txt",a,n,m);
print(a,n,m);
return 0;
}

0 comments on commit d7e9852

Please sign in to comment.