O’ZBEKISTON RESPUPLIKASI AXBOROT TEXNALOGIYALARI VA
KOMMUNUKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT
AXBOROTTEXNOLOGIYALARI UNIVERSITETI
TELEKOMMUNIKATSIYALAR FAKULTETI
DASTURLASH 2
Bajardi: 830-22- guruh talabasi
Eshqobilov Xushnudbek
Tekshi: Gulyamova Dilfuza
TOSHKENT 2023
Berilgan vazifalarni bajarishda kiruvchi qiymatlar matinli fayldan o’qib olinishi kerak.
1.Topshiriq. Berilgan float turidagi to’plam qiymatlarining butun(nuqtadan oldin) qismi 2- to’plamga, kasr(nuqtadan keyin) qismi 3- to’plamga joylashtiruvchi va ularni ekranga chiqaruvchi dastur tuzing. Ikkala to’plamdan ham bir xil qiymatli elemetlar o’chirilib Saralangan to’plam hosil qilinsin hamda uning qiymatlari ekranga chiqarilsin.
#include
#include
#include
#include
#include
#include
using namespace std;
void prepareTextFileToReadParametrs() {
srand(time(NULL));
fstream file;
file.open("TextFile.txt", ios::out);
if (file.is_open()) {
int l = rand() % 10 + 5;
for (int i = 0; i < l; i++)
file << (1.0 * (rand() % 10000)) / 100.0 << endl;
file.close();
}
cout << "The file named \"TextFile.txt\" is filled randomly!\n" << endl;
}
void print(set s) {
for (auto it = s.begin(); it != s.end(); it ++)
cout << *it << "\t";
}
int main() {
prepareTextFileToReadParametrs();
fstream file;
set s, s1, s2;
string line;
file.open("TextFile.txt", ios:: in);
if (file.is_open()) {
while (getline(file, line))
s.insert(stof(line));
file.close();
}
cout << "The set of float numbers that read from file is below 👇\n";
print(s);
for (auto it = s.begin(); it != s.end(); it++) {
s1.insert((int) *it);
s2.insert(((int)(*it * 100)) % 100);
}
cout << "\n\nThe set of Numbers before point! 👇\n";
print(s1);
cout << "\n\nThe set of Numbers after point! 👇\n";
print(s2);
set res;
for (auto it = s1.begin(); it != s1.end(); it++)
res.insert(*it);
for (auto it = s2.begin(); it != s2.end(); it++)
res.insert(*it);
cout << "\n\nThe result of thwo merged sets is following.👇\n";
print(res);
return 0;
}
2. Topshiriq.
#include
#include
#include
#include
#include
#include
#include
Do'stlaringiz bilan baham: |