Additions and updates in 1sem/PB
This commit is contained in:
parent
df67329dea
commit
e9d7aa3900
7 changed files with 189 additions and 7 deletions
28
1sem/programming basics/z15/43.cpp
Normal file
28
1sem/programming basics/z15/43.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// pb_z15_43.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <climits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void reverse_uchar(std::iostream &ost);
|
||||
|
||||
int main() {
|
||||
fstream iof("out.bin", ios::in|ios::out|ios::binary);
|
||||
if (!iof.is_open())
|
||||
{
|
||||
cerr << "Unable to open file" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
reverse_uchar(iof);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reverse_uchar(std::iostream &ost) {
|
||||
unsigned char cval = UCHAR_MAX;
|
||||
for (int i = 0; i <= cval; i++) {
|
||||
ost << cval--;
|
||||
}
|
||||
}
|
||||
30
1sem/programming basics/z15/44.cpp
Normal file
30
1sem/programming basics/z15/44.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// pb_z15_44.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void uchar_add(std::iostream &ost, unsigned char v);
|
||||
|
||||
int main() {
|
||||
fstream iof("out.bin", ios::in|ios::out|ios::binary);
|
||||
if (!iof.is_open())
|
||||
{
|
||||
cerr << "Unable to open file" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char v;
|
||||
cout << "Char >>>";
|
||||
cin >> v;
|
||||
uchar_add(iof, v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uchar_add(std::iostream &ost, unsigned char v) {
|
||||
while (!ost.eof() && ost.good()) {
|
||||
unsigned int out = (unsigned char)ost.get() + v;
|
||||
ost << (unsigned char)(out > 255? char(255) : char(out));
|
||||
}
|
||||
}
|
||||
0
1sem/programming basics/z15/45.cpp
Normal file
0
1sem/programming basics/z15/45.cpp
Normal file
Loading…
Add table
Add a link
Reference in a new issue