Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Zvit.doc
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
1 Мб
Скачать
☆

Return 0;

}

int f_2(int **b, int m, int n)

{ int l,k=0,y,z,sum=0,buf=0;

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {

if (b[i][j]==0) { l=i;

for (j = 0; j < m; j++) {

if (b[l][j]<0) k++;

}

cout<<"\nThere are <"<<k<<"> negative elements in the <"<<l<<"> raw.\n";

k=0;

}

}

}

bool t = false;

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {

if (b[i][j] >= 0) {

y=i;z=j; buf = b[i][j]; t = true;break;

}

}

if (t) break;

}

t = false;

for (int i = 0; i < n; i++)

for (int j = 0; j < m; j++) {

if(!t && b[i][j] == b[y][z]) t = true;

if (t) sum += abs(b[i][j]);

}

sum = b[y][z];

cout<<"\n\nThe sum of elements that goes after <"<<buf<<"> = "<<sum<<endl;

return 0;

}

int f_3(char* s)

{ int p=0, k=0,li=0;

int i,l,count = 0;

l = strlen(s);

for (i = 0; s[i] != '\0'; i++)

if (!isspace(s[i]) && !ispunct(s[i]))

{

count++;

while (isalpha(s[i+1]) || isdigit(s[i+1]))

i++;

}

cout<<"\nAmount of words : "<<count<<endl;

int lp;

for (int i = 0; s[i] != '\0'; i++){

p++;

if (p>k) {

k=p;

lp = i-k+1;

}

if (s[i]=='.'||s[i]=='?'||s[i]=='!')

{

p=0;

}

}

char string[80];

for (int i = 0; i < 79; i++) {

string[i]=NULL;

}

int o = 0;

for (int j = lp; j <= lp+k; j++)

{

string[o] = s [j]; o++;

}

cout<<"\n\nThe longest sentence is : ";

for (int i = 0; i < k; i++) {

cout<<string[i];

}

cout<<"\nAnd it has "<<k<<" symbols.";

for (int i = 0; s[i] != '\0'; i++) {

if (s[i]=='e'||s[i]=='y'||s[i]=='u'||s[i]=='i'||s[i]=='o'||s[i]=='a'||s[i]=='E'||s[i]=='Y'||s[i]=='U'||s[i]=='I'||s[i]=='O'||s[i]=='A') {

if (isalpha(s[i-1]) && isalpha(s[i+1]) && (ispunct(s[i+2])||isspace(s[i+2]))) {

for (int j = i+1; !ispunct(s[j])&&!isspace(s[j]); j--) {

s[j] = '0';

}

}

}

}

Char st[80];

for (int i = 0; i < 79; i++) {

st[i]= NULL;

}

for (int i = 0; s[i] != '\0'; i++){

if (s[i]!='0') st[i]=s[i];

}

cout<<"\n\nOutput text : ";

for (int i = 0; s[i] != '\0'; i++){cout<<st[i];}

}

Int main() {int n; double c;

cout<<"\n<1>\n\n\nSize of array : ";

cin>>N;

double *a = new double [N];

cout<<"\nPut down the constant for comparison : ";

cin>>C;

cout<<"\nPut down "<<N<<" elements of array :\n";

for (int i = 0; i < N; i++) {

cout<<"\n"<<i<<") ";

cin>>a[i];

}

f_1(a, N, C);

cout<<"\n\n\n<2>\n\n";

int m,n,g;

cout<<"\nSize of matrix : \n"; cin>>m; cout<<"x\n"; cin>>n;

g = m*n;

int **mas = new int *[n];

for (int i = 0; i < n; i++) {

mas[i] = new int [m];}

cout<<"\n\nPut down "<<g<<" elemens of maxtix : \n";

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {

cin>>mas[i][j];

}

cout<<"\n";

}

cout<<"\n\nYou entered the next matrix : \n\n";

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {

cout<<mas[i][j]<<" ";

}

cout<<"\n\n";

}

f_2(mas,m,n);

char str[80];

cout<<"\n\n\n<3>\n\n";

cout<<"\nType text here :\n";

cin.get();

cin.getline(str,80);

f_3(str);

cout<<"\n\n";

system("pause");

return 0;

}

//---------------------------------------------------------------------------

Додаток D

Лістинг 4А

//---------------------------------------------------------------------------

#pragma hdrstop

#include <iostream.h>

#include <tchar.h>

#include <string>

using namespace std;

//---------------------------------------------------------------------------

#pragma argsused

int f(double **a, int n)

{

int* sum_r = new int [n];

int* sum_s = new int [n];

int s;

for (int i = 0; i < n; i++) { s=0;

for (int j = 0; j < n; j++) {

s = s + a[i][j];

sum_r[i] = s;

}

}

for (int i = 0; i < n; i++) { s=0;

for (int j = 0; j < n; j++) {

s = s + a[j][i];

sum_s[i] = s;

}

}

cout<<"\nResult :\n";

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

if (sum_r[i] == sum_s[j]) {

cout<<i<<" raw = "<<j<<" column\n\n";

}

}

}

int l;

for (int i = 0; i < n; i++) {s = 0; l = 0;

for (int j = 0; j < n; j++) {

if (a[i][j] != 0) {

s = s + a[i][j];

l++;

}

}

if(l>=2) cout<<"\n\nThe sum of elements in the "<<i<<" raw = "<<s;

}

return 0;

}

enum gender {Male = 1, Female = 2};

struct ABITURIENT

{

string NAME;

gender GENDER;

string SPEC;

int EXAM[3];

double SB;

ABITURIENT& operator=(ABITURIENT &a){

NAME =a.NAME;

GENDER =a.GENDER;

SPEC = a.SPEC;

EXAM[0] = a.EXAM[0];

EXAM[1] = a.EXAM[1];

EXAM[2] = a.EXAM[2];

SB = a.SB;

}

};

int main()

{

int N;

double B;

cout<<"Amount of students : ";

cin>>N;

cout<<"Needed result of 3 exams : ";

cin>>B;

cin.get();

ABITURIENT*ab;

ab = new ABITURIENT [N];

ABITURIENT buf;

ABITURIENT min;

for (int i = 0; i < N; i++) {

cout<<"Type name of the "<<i+1<<" student : ";

getline(cin, ab[i].NAME);

int ge;

do {

cout<<"Type gender of the "<<i+1<<" student (1 = Male, 2 = Female) : ";

cin>>ge;

}

while (ge<1 || ge>2);

ab[i].GENDER = (gender)ge;

cout<<"The name of speciality : ";

cin.get();

getline(cin, ab[i].SPEC);

cout<<"Type the results of the 3 exams : ";

for (int j = 0; j < 3; j++) {

cin>>ab[i].EXAM[j];

}

ab[i].SB = (ab[i].EXAM[0] + ab[i].EXAM[1] + ab[i].EXAM[2])/3.0;

system("cls");

}

cout<<"Name\tGender\tSpeciality\tResults of exams\n\n";

for (int i = 0; i < N; i++) {

cout<<ab[i].NAME<<'\t';

switch (ab[i].GENDER) {

case Male: cout<<"Male"; break;

case Female: cout<<"Female"; break;

}

cout<<'\t'<<ab[i].SPEC<<"\t\t";

for (int j = 0; j < 3; j++) {

cout<<ab[i].EXAM[j]<<'\t';

}

cout<<'\n';

}

cout<<"\n\nOrdered table :\n";

for (int i = 0; i < N; i++) {

for (int j = N-1; j > i; j--) {

if (ab[j-1].NAME > ab[j].NAME) {

buf = ab[j-1];

ab[j-1] = ab[j];

ab[j] = buf;

}

}

}

cout<<"Name\tGender\tSpeciality\tResults of exams\n\n";

for (int i = 0; i < N; i++) {

cout<<ab[i].NAME<<'\t';

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]