Портал образовательно-информационных услуг «Студенческая консультация»

  
Телефон +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
Язык: 
Українська
Оценка: 
1.Програма зчитує з файлу дві матриці, додає , множить (якщо це можливо) розв’язок виводить на екран, та записує у файл.
 
#include <iostream>
#include <fstream>
#include "windows.h"
using namespace std;
void tofile(ofstream& fout, float** A,int n, int m)
{
for (int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
fout<<A[i][j]<<" ";
}
fout<<'\n';
}
fout<<'\n';
}
float** fromfile(ifstream& fin,int& n, int& m)
{
int pos=fin.tellg();
int k;
int c;
n=0;
m=0;
bool p=true;
while(p)
{
fin>>c;
m++;
if (fin.get()=='\n') 
{
++n;
if (fin.get()=='\n') p=false;
else{ k=fin.tellg();k--; fin.seekg(k);}
};
};
m/=n;
float **A=new float *[n];
for (int i=0;i<n;i++)
{
A[i]=new float [m];
};
fin.seekg(pos);
for (int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
fin>>A[i][j];
fin.get();
}
}
fin.get();
return A;
void output(float** A,int n, int m)
{if (A!=NULL)
{
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
cout<<A[i][j]<<flush<<" ";
cout<<endl;
}
cout<<endl;
}
}
float** ADD(float** A, float** B, int n1,int n2,int m1,int m2)
{
if ((n1==n2)&&(m1==m2))
{float **C = new float *[n1];
for (int i=0;i<n1;i++)
C[i]= new float [m1];
for(int i=0;i<n1;i++)
for(int j=0;j<m1;j++)
C[i][j]=A[i][j]+B[i][j];
return C;
}
else 
{
cout<<"ADD is not possible"<<endl;
return NULL;
}
}
float** MUL(float** A, float** B, int n1, int n2, int m1, int m2)
{
if (m1==n2)
{
float **C = new float *[n1];
for (int i=0;i<n1;i++)
C[i] = new float [m2];
for (int i=0;i<n1;i++)
{
for(int j=0;j<m2;j++)
{
C[i][j] = 0;
for(int k=0;k<m1;k++)
{
C[i][j]+=(A[i][k]*B[k][j]);
}
}
}
return C;
}
else 
{
cout<<"MUL is not possible"<<endl;
return NULL;
}
}
int main()
{
SetConsoleOutputCP(1251);
ifstream fin("input.txt");
ofstream fout;
fout.open("output.txt");
float **A,**B, **C ,**D;
int n1,n2,n3,m1,m2,m3,n4,m4;
int n,m,pos;
cout<<"Вхідні дані:\nA:\n";
A=fromfile(fin,n1,m1);
output(A,n1,m1);
B=fromfile(fin,n2,m2);
cout<<"B:\n";
output(B,n2,m2);
C=ADD(A,B,n1,n2,m1,m2);
D=MUL(A,B,n1,n2,m1,m2);
cout<<"Результат:\nA+B:\n";
if (C!=NULL)
{
n3=n1;
m3=m1;
output(C,n3,m3);
tofile(fout,C,n3,m3);
}
cout<<"A*B\n";
if (D!=NULL)
{
n4=n1;
m4=m2;
output(D,n4,m4);
tofile(fout,D,n4,m4);
}
fin.close();
fout.close();
cin.get();
cin.get();
return 0;
}
2. Програма яка видаляє з рядку всі слова які починаються та закінчуються на одну й ту саму букву, рядок вводимо з клавіатури.
 
#include <iostream>
#include <string>
#include "windows.h"
using namespace std;
void edit(string& s)
{
string ss="", word="";
int i=0;
while(i<s.length())
{
if(isalpha((unsigned char) s[i]))
{
while (isalpha((unsigned char)s[i]) && i<s.length()) {word+=s[i]; if (i==s.length()-1)  break; else i++;}
if (word[0]!=word[word.length()-1]) ss+=word;
else i++;
word="";
else {ss+=s[i];i++;}
}
s=ss;
}
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;
}
 
3.Програма сортує слова у рядку, рядок вводимо з клавіатури.
 
#include <iostream>
#include <string>
#include "windows.h"
using namespace std;
void sort(string& s)
{
string ss="", word="";
int i=0;
int k=0;
s+=" ";
while(i<s.length())
{
if(isalpha((unsigned char) s[i]))
{
while (isalpha((unsigned char)s[i]) && i<s.length()) {word+=s[i]; if (i==s.length()-1)  break; else i++;}
k++;
word="";
else {i++;}
}
string *smas=new string [k];
i=0;
k=0;
while(i<s.length())
{
if(isalpha((unsigned char) s[i]))
{
while (isalpha((unsigned char)s[i]) && i<s.length()) {word+=s[i]; if (i==s.length()-1)  break; else i++;}
smas[k++]=word;
word="";
else {i++;}
}
s="";
string s5="";
for(int j=0;j<k-1;j++)
{for(int l=0;l<k-j-1;l++)
{if (smas[l+1]<smas[l]) {s5=smas[l]; smas[l]=smas[l+1]; smas[l+1]=s5;}}}
for(int j=0;j<k;j++)
s+=smas[j]+" ";
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
string s,a;
cout<<"Введіть рядок:\n";
getline(cin,s);
sort(s);
cout<<"Редагований рядок:"<<endl;
cout<<s;
cin.get();
cin.get();
return 0;
}
 
4.Програма, яка у кожному слові рядка переставляє усі цифри в кінець слова, без зміни порядку.
 
#include <iostream>
#include <string>
#include "windows.h"
using namespace std;
void edit(string& s)
{
string ss="", word="", digit="";
int i=0;
while(i<s.length())
CAPTCHA на основе изображений