Skip to content

Commit

Permalink
Add source code of Lesson 7
Browse files Browse the repository at this point in the history
  • Loading branch information
lamhoangtung committed Jul 24, 2018
1 parent 8ae1a4f commit d85dcfb
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Bai thuc hanh so 7/bai1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <fstream>

using namespace std;

int main(){
ifstream InputFile("FIRSTFILE.txt");
string s;
while (getline(InputFile,s)){
cout << s << endl;
}
InputFile.close();
return 0;
}
28 changes: 28 additions & 0 deletions Bai thuc hanh so 7/bai2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <fstream>

using namespace std;

int main(){
ofstream ofile1,ofile2;
ofile1.open("FILE1.txt");
ofile1 << "7 2\n1 2 3 1\n2 2 4 1\n3 3 5 1\n";
ofile1.close();
ofile2.open("FILE2.txt");
ofile2 << "4 1 1 2\n5 2 2 2\n6 3 3 2\n7 4 4 2\n";
ofile2.close();
ifstream ifile1("FILE1.txt");
ifstream ifile2("FILE2.txt");
ofstream ofile3("FILE3.txt");
ofile3 << ifile1.rdbuf() << ifile2.rdbuf();
ifile1.close();
ifile2.close();
ofile3.close();
ifstream ifile3("FILE3.txt");
string s;
while (getline(ifile3,s)){
cout << s << endl;
}
ifile3.close();
return 0;
}
42 changes: 42 additions & 0 deletions Bai thuc hanh so 7/bai3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <fstream>

using namespace std;

int main(){
int n,m;
cout << "Nhap n: ";
cin >> n;
cout << "Nhap m: ";
cin >> m;
ofstream ofile;
ofile.open("MATRIX.txt");
ofile << 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 << " ";
}
ofile << endl;
}
ofile.close();

int a[1000][1000];
ifstream ifile("MATRIX.txt");
ifile >> n >> m;
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
ifile >> a[i][j];
}
}
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;
}
return 0;
}
38 changes: 38 additions & 0 deletions Bai thuc hanh so 7/bai4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <fstream>

using namespace std;

int main(){
int n;
cout << "Nhap so phan tu cua mang: ";
cin >> n;
int a[n];
for (int i=0;i<n;i++){
cout << "Nhap phan tu thu " << i+1 << " cua mang: ";
cin >> a[i];
}
ofstream ofile;
ofile.open("DATHUC.txt");
ofile << n << endl;
for (int i=0;i<n;i++){
ofile << a[i] << " ";
}
ofile << endl;
for (int i=0;i<n;i++){
ofile << a[i] << " x " << i;
if (i!=n-1){
ofile << " + ";
}
else ofile << "." << endl;
}
ofile.close();

ifstream ifile("DATHUC.txt");
string s;
while (getline(ifile,s)){
cout << s << endl;
}
ifile.close();
return 0;
}

0 comments on commit d85dcfb

Please sign in to comment.