Портал освітньо-інформаційних послуг «Студентська консультація»

  
Телефон +3 8(066) 185-39-18
Телефон +3 8(093) 202-63-01
 (093) 202-63-01
 studscon@gmail.com
 facebook.com/studcons

<script>

  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

 

  ga('create', 'UA-53007750-1', 'auto');

  ga('send', 'pageview');

 

</script>

Звіт з навчальної практики "Об’єктно-орієнтоване програмування, програмне забезпечення"

Тип роботи: 
Звіт з практики
К-сть сторінок: 
46
Мова: 
Українська
Оцінка: 

justify;">{

if(isalnum((unsigned char)s[i]))
{
if (s[i]==' ') break;
while (isalnum((unsigned char)s[i]) && i<s.length()) 
{
if (s[i]==' ') break;
if (isdigit((unsigned char)s[i])) digit+=s[i];
else word+=s[i]; 
if (i==s.length()-1)  break;else i++;
}
ss=ss+word+digit+" ";
digit="";
word="";
i++;
else {ss+=s[i];i++;}
}
for (int i=0; i<ss.length()-1;i++)
s[i]=ss[i];
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
string s,a;
cout<<"Введіть рядок:\n";
getline(cin,s);
edit(s);
cout<<"Редагований рядок:"<<endl;
cout<<s;
cin.get();
cin.get();
return 0;
}
 
5. Програма, яка з заданого масиву виводить на екран ті елементи які є степенями двійки. Для введення масиву та перевірки елементу ми використовуємо покажчики на функцію, передаючи їх параметрами функції.
 
#include <iostream>
#include "windows.h"
using namespace std;
double* input(int n)
{
double *mas=new double [n];
for(int i=0;i<n;i++)
{
cout<<"mas["<<i+1<<"]=";
cin>>mas[i];
}
return mas;
}
bool check(double a)
{
bool p=false;
for (double i=1;i<=1000;i++)
if (a==pow(2,i)) { p=true; break;}
return p;
}
void dosmth(int n, bool (*p1)(double), double* (*p2)(int))
{
double* mas=p2(n);
cout<<"Результат:"<<endl;
for (int i=0;i<n;i++)
if (p1(mas[i])) cout<<mas[i]<<" ";
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
bool (*f1)(double);
double* (*f2)(int);
f1=check;
f2=input;
int n=0;
while (n<=0) 
{
cout<<"Введіть кількість n=";
cin>>n;
}
dosmth(n,f1,f2);
cin.get();
cin.get();
return 0;
}
 
6. Програма, яка зчитує з файлу структури, в яких міститься інформація про об’єкти, записує кожну структуру в окремий файл,  сортує їх(подвійне сортування), та від сортовані структури записує у файл.
 
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include "windows.h"
using namespace std;
typedef struct
{
string name;
string type;
}port;
typedef struct
{
string producer;
string category;
int portcount;
float priority, price;
port* ports;
}product;
void tofile(ofstream& fout,product p)
{
fout<<p.category<<endl;
fout<<p.producer<<endl;
fout<<p.priority<<endl;
fout<<p.price<<endl;
fout<<p.portcount<<endl;
for (int i=0;i<p.portcount;i++)
{
fout<<p.ports[i].name<<endl;
fout<<p.ports[i].type<<endl;
}
}
void printout(product& p)
{
cout<<p.category<<endl;
cout<<p.producer<<endl;
cout<<p.priority<<endl;
cout<<p.price<<endl;
cout<<p.portcount<<endl;
for(int i=0; i<p.portcount;i++)
{
cout<<p.ports[i].name<<endl;
cout<<p.ports[i].type<<endl;
}
cout<<endl;
}
product* fromfile(ifstream& fin, int& n)
{
int k=0;
product p;
while (!fin.eof())
{
getline(fin,p.category);
getline(fin,p.producer);
fin>>p.priority;
fin>>p.price;
fin>>p.portcount;
fin.get();
for(int i=0; i<p.portcount;i++)
{
getline(fin,p.producer);
getline(fin,p.producer);
}
fin.get();
k++;
}
n=k;
product* A=new product[n];
k=0;
fin.clear();
fin.seekg(0);
while (!fin.eof())
{
getline(fin,p.category);
getline(fin,p.producer);
fin>>p.priority;
fin>>p.price;
fin>>p.portcount;
fin.get();
p.ports = new port [p.portcount];
for(int i=0; i<p.portcount;i++)
{
getline(fin,p.ports[i].name);
getline(fin,p.ports[i].type);
}
fin.get();
A[k]=p;
k++;
}
return A;
}
 
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int n,a,b;
product* A;
ifstream fin("input.txt");
A=fromfile(fin,n);
for(int i=0;i<n;i++)
{
std::stringstream out;
out << i;
string s= out.str();
s="product"+s+".txt";
ofstream fout(s);
tofile(fout,A[i]);
fout.close();
}
cout<<"сортувати за ціною введіть 0, за пріорітитем введіть інше ціле число ";
cin>>a;
 
if (a!=0)
{for (int j=0;j<n-1;j++)
{
for(int i=0;i<n-1;i++)
if (A[i].priority>A[i+1].priority) {product p=A[i]; A[i]=A[i+1]; A[i+1]=p;}
}
}
else 
{for (int j=0;j<n-1;j++)
{
for(int i=0;i<n-1;i++)
if (A[i].price>A[i+1].price) {product p=A[i]; A[i]=A[i+1]; A[i+1]=p;}
}
};
cout<<"сортувати за категорією введіть 0, за виробником введіть інше ціле число ";
cin>>b;
if (b==0)
{for (int j=0;j<n-1;j++)
{
for(int i=0;i<n-1;i++)
if (A[i].category>A[i+1].category) {product p=A[i]; A[i]=A[i+1]; A[i+1]=p;}
}
}
else
{for (int j=0;j<n-1;j++)
{
for(int i=0;i<n-1;i++)
if (A[i].producer>A[i+1].producer) {product p=A[i]; A[i]=A[i+1]; A[i+1]=p;}
}
};
ofstream fout("sorteddata.txt");
for (int i=0;i<n;i++)
{
tofile(fout,A[i]);
if (i!=n-1) fout<<endl;
printout(A[i]);
}
fout.close();
cin.get();
cin.get();
fin.close();
return 0;
}
 
7. Програма, яка за допомогою класу працює зі стеком, додає елемент у стек, забирає елемент зі стеку, додає вектор у стек, видаляє усі елементи зі стеку, перевіряє чи стек не пустий.
 
struct list
{
int val;
struct list* next;
};
 
class Stack
{
private:
struct list* item;
public:
Stack();
~Stack();
bool
Фото Капча