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

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\n\nStudents wich got good results :\n\n";

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

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

if (ab[i].SB >= B) {

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';

}

} int n;

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

cout<<"Type size of square matrix : ";

cin>>n;

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

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

mas[i] = new double [n];}

cout<<"\n\nType elements of matrix :\n";

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

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

cin>>mas[i][j];

}

cout<<"\n";

}

f(mas,n);

cout<<"\n\n";

system("pause");

return 0;

}

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

Додаток Е

Лістинг 5А

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

#pragma hdrstop

#include <tchar.h>

#include <string>

#include <fstream>

#include <iostream>

#include <windows.h>

#include <cstdlib>

#include <algorithm>

#include <vector>

#include <cctype>

using namespace std;

char bufRus[256];

char* Rus(const char* text) {

CharToOem(text, bufRus);

return bufRus;

}

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

struct ITINERARY{

string FIRST;

string FINAL;

int NUM;

int DISTANCE;

friend ostream& operator<< (ostream& out, ITINERARY& T){

cout<<Rus("\nПочаток маршруту\n");

out<<T.FIRST;

cout<<Rus("\nКiнець маршруту\n");

out<<T.FINAL;

cout<<Rus("\nНомер маршруту\n");

out<<T.NUM;

cout<<Rus("\nДистанцiя маршруту\n");

out<<T.DISTANCE;

return out;

}

//Ввід структури

friend istream& operator>> (istream& in, ITINERARY& T){

//char s[80];

cout<<Rus("\nПочаток маршруту\n");

//in.get();

in>>T.FIRST;

//T.FIRST.operator =(s);

cout<<Rus("\nКiнець маршруту\n");

//in.get();

in>>T.FINAL;

//

//in.getline(s,80);

//T.FINAL.operator =(s);

cout<<Rus("\nНомер маршруту\n");

in>>T.NUM;

cout<<Rus("\nДистанцiя маршруту\n");

in>>T.DISTANCE;

return in;

}

};

void double_point(string s, ofstream& f)

{

int k;

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

if (s[i]==':') {

k = i;

//break;

f<<"\nТекст пiсля двокрапки : ";

for (int j = k+1; s[j] != '\0'; j++) {

f<<s[j];

}

}

}

}

void sentence_counter ( string s, ofstream& f)

{ int k1=0;

for (int i = 0; i < '\0'; i++) {

if (isalpha(s[i])||isdigit(s[i])) {k1++; }

else if (isspace(s[i])||ispunct(s[i])) { }

}

}

//прототипи функцій

void copy_paste(string , ofstream& );

void max_word(string,ofstream& );

//void lower_to_super(string ,ofstream& );

void word_del(string,ofstream& );

int words_finder(string,ofstream&);

//прототипи функцій для роботи із БД

void BD_DELETE(vector<ITINERARY>&);

void BD_ELEMENT_DELETE(vector<ITINERARY>&,int);

void BD_FIND_ELEMENT(string,string,vector<ITINERARY>&);

void BD_FIND_ELEMENT(int,string,vector<ITINERARY>&);

ITINERARY BD_ELEMENT_EDIT();

ITINERARY BD_ELEMENT_EDIT(string,string,int,int);

#pragma argsused

int _tmain(int argc, _TCHAR* argv[])

{

//файлові змінні

ofstream fout;

ifstream fin;

fin.open("input.txt");

fout.open("output.txt");

char st[80];

if(!fin)

{

cout<<Rus("\nНеможливо вiдкрити файл для читання\n");

system("pause");

return 1;

}

//читання рядку з файлу

fin.getline(st,sizeof(fin));

//перша частина програми

copy_paste(st,fout);

// lower_to_super(st,fout);

double_point(st, fout);

// max_word(st,fout);

word_del(st,fout);

fout<<"\n"<<words_finder(st,fout)<<"\n";

fin.close();

fout.close();

/*

//друга частина програми і робота із БД

ofstream struct_fout("struct_file.txt");

int n;

ITINERARY c;

cout<<Rus("Введiть кiлькiсть маршрутiв")<<endl;

cin>>n;

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

cin>>c;

struct_fout<<c.FIRST.c_str()<<endl;

struct_fout<<c.FINAL.c_str()<<endl;

struct_fout<<c.NUM<<endl;

struct_fout<<c.DISTANCE<<endl;

}

struct_fout.close();

vector<ITINERARY> v;

ifstream struct_fin("struct_file.txt");

if(!struct_fin)

{

cout<<Rus("\nНе можливо вiдкрити файл для читання");

system("pause");

return 1;

}

char str[80];

for (int i = 0; i < sizeof(struct_fin); i += 4) {

struct_fin.getline(str,80);

c.FIRST = str;

struct_fin.getline(str,80);

c.FINAL = str;

struct_fin>>c.NUM;

struct_fin>>c.DISTANCE;

v.push_back(c);

}

struct_fin.close();

int l;

cout<<Rus("Введiть номер елемента який потрiбно змiнити");

cin>>l;

v[l] = BD_ELEMENT_EDIT("Chernivtsi","Kyiv",1,584);

cout<<Rus("Введiть номер елемента який потрiбно змiнити\n");

cin>>l;

v[l] = BD_ELEMENT_EDIT();

BD_FIND_ELEMENT("Chernivtsi","FIRST",v);

cout<<Rus("Введiть номер елемента який потрiбно видалити\n");

cin>>l;

BD_ELEMENT_DELETE(v,l);

BD_DELETE(v); */

system("pause");

return 0;

}

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

void copy_paste (string s, ofstream& f){

f<<"Введений рядок\n"<<s<<endl;

}

/*

void max_word(string s, ofstream& f){

int max_length = 0,max_i = 0;

vector<string> Words_list = words_finder(s);

for (int i = 0; i < Words_list.size(); i++) {

if (Words_list[i].length() > max_length)

{

max_length = strlen(Words_list[i].c_str());

max_i = i;

}

}

f<<"\n Найбiльше слово - "<<Words_list[max_i]<<endl;

}

*/

int words_finder(string s, ofstream& f) {

vector<string > Sl;

Sl.~vector();

string S = "";

int l = 0;

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

{

if (!isspace(s[i]) && !ispunct(s[i])) S += s[i];

else

if(S != ""){

Sl.push_back(S);

S = "";

}

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

int u = Sl.size();

if(u%2) {l++;Sl.~vector();}

}

}

if (S != "") Sl.push_back(S);

f<<"\nК-сть речень з непарною к-стю слів : ";

return l;

}

void word_del(string s,ofstream& f){

//vector <string> Words_list = words_finder(s);

int i,j,vowels_i;

string S;

bool koma = false;

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

if(koma && isspace(s[i]) && ispunct(s[i])) koma = false;

else

if(!koma && s[i] != ','){continue;}

else if(!koma && s[i] == ',') {

koma = true;}

else if (koma && !isspace(s[i]) && !ispunct(s[i])) {S += s[i];continue;}

else if(koma && S != "") {koma = 0;s.erase(s.find(S),S.length()); S = "";}

}

f<<"\nРядок утворений пiсля вилучення лишнiх слiв\n"<<s;

}

void BD_DELETE(vector<ITINERARY>& V) {

V.~vector();

}

void BD_ELEMENT_DELETE(vector<ITINERARY>& V,int elem) {

V.erase(V.begin() + elem);

}

ITINERARY BD_ELEMENT_EDIT() {

ITINERARY RES;

char c[80];

cin.get();

cout<<Rus("Введiть початок маршруту");

cin.getline(c,80);

RES.FIRST = c;

cout<<Rus("Введiть кiнець маршруту");

cin.getline(c,80);

RES.FINAL = c;

cout<<Rus("Введiть номер маршруту");

cin>>RES.NUM;

cout<<Rus("Введiть дистанцiю маршруту");

cin>>RES.DISTANCE;

return RES;

}

ITINERARY BD_ELEMENT_EDIT(string first,string final,int num,int distance) {

ITINERARY RES;

RES.FINAL = final;

RES.FIRST = first;

RES.NUM = num;

RES.DISTANCE = distance;

return RES;

}

void BD_FIND_ELEMENT(string needed,string s,vector<ITINERARY>& V){

int i,l = 0;

cout<<Rus("Елементи знайденi пошуком");

if (s == "FIRST"){

for (i = 0; i < V.size(); i++) {

if (needed == V[i].FIRST) {

l++;

cout<<V[i];

}

}

}

else if (s == "FINAL") {

for (i = 0; i < V.size(); i++) {

if (needed == V[i].FINAL) {

l++;

cout<<V[i];

}

}

}

else if( !l) cout<<Rus("Збiгiв не знайдено!!!");

else cout<<Rus("Невiрно заданий параметр пошуку");

}

void BD_FIND_ELEMENT(int needed,string s,vector<ITINERARY>& V) {

int i,l = 0;

cout<<Rus("Елементи знайденi пошуком");

if (s == "NUM"){

for (i = 0; i < V.size(); i++) {

if (needed == V[i].NUM) {

l++;

cout<<V[i];

}

}

}

else if (s == "DISTANCE") {

for (i = 0; i < V.size(); i++) {

if (needed == V[i].DISTANCE) {

l++;

cout<<V[i];

}

}

}

else if(!l) cout<<Rus("Збiгiв не знайдено!!!");

else cout<<Rus("Невiрно заданий параметр пошуку");

}Додаток F

лістинг 6А

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

#pragma hdrstop

#include <tchar.h>

#include "my_class.h"

#include "rus.h"

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

#pragma argsused

int _tmain(int argc, _TCHAR* argv[])

{

file f;

unsigned int n,bool_n;

cout<<Rus("Cтворити БД зараз? (X = ТАК | 0 = НI)");

cin>>bool_n;

if(bool_n){

cout<<Rus("\n Введiть кiлькiсть елементiв\n");

cin>>n;

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

f.BD_ADD_ELEMENT(f);

}

}

m:

cout<<Rus("\nМеню програми:\n<1> - введення даних через сетери і гетери");

cout<<Rus("\n<2> - введення даних через конструктори");

cout<<Rus("\n<3> - виведення даних на екран");

cout<<Rus("\n<4> - пошуку даних");

cout<<Rus("\n<5> - сортування даних в БД");

cout<<Rus("\n<6> - додавання елемента в БД");

cout<<Rus("\n<7> - видалення елемента iз БД");

cout<<Rus("\nдовiльне iнше число - вихiд \n");

int sw;

cin>>sw;

switch(sw){

case 1:

{

Date d;

d.day = 12;

d.month = 10;

d.year = 2013;

file fi;

cout<<"\n__________________________________________________\n";

fi.set_date(d);

fi.set_name("project_1");

fi.set_type(".exe");

cout<<fi.get_date().day

<<endl

<<fi.get_date().month

<<endl

<<fi.get_date().year

<<endl

<<fi.get_name()

<<endl

<<fi.get_type()

<<endl

<<fi.get_size()

<<endl

<<fi.get_atr() ;

f.BD_ADD_ELEMENT(fi);

goto m;}

case 2:

{

file fi;

f.BD_ADD_ELEMENT(fi);

cout<<"\n__________________________________________________\n";

cout<<fi;

goto m;

}

case 3:

{cout<<"\n__________________________________________________\n";

f.BD_SHOW();

goto m;}

case 4:

{

cout<<"\n__________________________________________________\n";

cout<<"_ _ _ _ _ _ _ \n";

f.BD_FIND_ELEMENT("Music","name");

cout<<"_ _ _ _ _ _ _ \n";

f.BD_FIND_ELEMENT(3,"volume");

cout<<"_ _ _ _ _ _ _ \n";

Date t;

f.BD_FIND_ELEMENT(t,"date");

goto m;

}

case 5:

{

cout<<"\n__________________________________________________\n";

f.BD_SORT("type");

f.BD_SHOW();

goto m;

}

case 6:

{

cout<<"\n__________________________________________________\n";

file fil;

string s;

unsigned int k;

Date d;

cout<<Rus("\nВведiть назву");

cin>>s;

fil.set_name(s);

cout<<Rus("\nВведiть тип");

cin>>s;

fil.set_type(s);

cout<<Rus("\nВведiть розмір");

cin>>k;

fil.set_size(k);

cout<<Rus("\nВведiть атрибути");

cin>>s;

fil.set_atr(s);

cout<<Rus("\nВведiть дату");

fil.set_date(d);

f.BD_ADD_ELEMENT(fil);

f.BD_SHOW();

goto m;

}

case 7:

{

cout<<"\n__________________________________________________\n";

int d;

cout<<Rus("\n Введiть номер елемента який потрiбно видалити\n");

cin>>d;

f.BD_ELEMENT_DELETE(d);

f.BD_SHOW();

goto m;

}

default :

f.BD_DELETE();

system("PAUSE");

return 0;

}

}

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

Додаток G

Лістинг 7А

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

#pragma hdrstop

#include <tchar.h>

#include <iostream>

#include "my_class.h"

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

#pragma argsused

int _tmain(int argc, _TCHAR* argv[])

{

ticket_list list;

ticket a("name",1.1,1.2,3.2,Date(01,02,2013),Date(01,02,2013)),b("name2",2.2,2.3,333),c;

list.add();

list.add(a);

list.add(b);

list.print();

list.find("name");

ticket pr("pr",100,100,100);

list.insert_after(pr,0);

list.print();

list.remove(1);

list.print();

system("pause");

return 0;

}

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

Лістинг 7В

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

#include <vcl.h>

#include "my_class.h"

#pragma hdrstop

#include "Unit1.h"

#include "Unit2.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

//TForm1 *Form1;

using GRAPH::Point;

using GRAPH::Square;

Square S;

unsigned int plus_x = 0,plus_y = 0,plus_side = 10,this_x = 30,this_y = 30,this_side = 30;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

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

void __fastcall TForm1::Button1Click(TObject *Sender)

{

S = Square(this_x,this_y,this_side);

this_x = S.get_x();

this_y = S.get_y();

this_side = S.get_side();

S.clear();

S.draw();

}

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

void __fastcall TForm1::Button2Click(TObject *Sender)

{

this_x = S.get_x();

this_y = S.get_y();

this_side = S.get_side();

S.resize(plus_side);

}

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

void __fastcall TForm1::Button3Click(TObject *Sender)

{

this_x = S.get_x();

this_y = S.get_y();

this_side = S.get_side();

S.remove(plus_x,plus_y);

}

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

void __fastcall TForm1::Button4Click(TObject *Sender)

{

//S = Square (30,30,30);

S.change_color();

}

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

void __fastcall TForm1::Button6Click(TObject *Sender)

{

Close();

}

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

void __fastcall TForm1::Button5Click(TObject *Sender)

{

Form2->Show();

}

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

Додаток H

Скріншоти програм

1

2

3

4

5

6

7

СПИСОК ВИКОРИСТАНОЇ ЛІТЕРАТУРИ

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