Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- struct Payment
- {
- char *name;
- char *date;
- int summ;
- };
- char* StringCopy(char* s)
- {
- char* Str = 0;
- int lenght = 0;
- for (int i = 0; s[i]; i++)
- lenght++;
- lenght++;
- Str = new char [lenght];
- for (int i = 0; i<lenght; i++)
- Str[i] = s[i];
- return Str;
- }
- Payment* Init(int n)
- {
- Payment* A = new Payment [n];
- return A;
- }
- void Delete(Payment* &A, int n)
- {
- for (int i = 0; i<n; i++)
- {
- delete [](A[i].name);
- delete [](A[i].date);
- }
- delete []A;
- A=0;
- }
- void DataInput(Payment* &A, int n)
- {
- const int N = 10000;
- char** Array = 0;
- int size = n;
- Array = new char* [size];
- cout << "Enter data : F_I_O_dd.mm.yy_summ" << endl;
- for (int i = 0; i<size; i++)
- {
- char TempString[N];
- cin.getline(TempString, N);
- Array[i] = StringCopy(TempString);
- }
- for (int i = 0; i<size; i++)
- {
- int spacesnum = 0, j = 0, q = 0;
- for (j = 0; Array[i][j]; j++)
- {
- if (Array[i][j]==' ')
- spacesnum++;
- if (spacesnum==3)
- break;
- }
- A[i].name = new char [j+1];
- for (int k = 0; k<j; k++)
- A[i].name[k] = Array[i][k];
- A[i].name[j]=0;
- j++;
- A[i].date = new char [9];
- for (int k = j; k<j+8; k++)
- A[i].date[k-j] = Array[i][k];
- A[i].date[8]=0;
- j=j+9;
- int lenght=0;
- for (int k = j; Array[i][k]; k++)
- lenght++;
- char* pay=0;
- int p = 0;
- pay = new char [lenght+1];
- for (int k = j; Array[i][k]; k++)
- pay[p++] = Array[i][k];
- pay[p] = 0;
- A[i].summ=atoi(pay);
- delete [] pay;
- }
- for (int i=0; i<size; i++)
- {
- delete [] Array[i];
- }
- delete [] Array;
- }
- void DataPrint(Payment* A, int n)
- {
- for (int i = 0; i<n; i++)
- cout << A[i].name << " " << A[i].date << " " << A[i].summ << endl;
- }
- void FindPeople(Payment* A, int n, char ch)
- {
- bool flag = false;
- for (int i = 0; i<n; i++)
- {
- if ((A[i].name[0]==toupper(ch))||(A[i].name[0]==tolower(ch)))
- {
- cout << A[i].name << " " << A[i].date << " " << A[i].summ << endl;
- flag = true;
- }
- }
- if (!flag)
- cout << "There are no such surnames." << endl;
- }
- void FindPay(Payment* A, int n, int s)
- {
- bool flag = false;
- for (int i = 0; i<n; i++)
- {
- if (A[i].summ > s)
- {
- cout << A[i].name << " " << A[i].date << " " << A[i].summ << endl;
- flag = true;
- }
- }
- if (!flag)
- cout << "There are no such payments." << endl;
- }
- void TotalPay(Payment* A, int n, char* d)
- {
- int sum = 0;
- for (int i = 0; i<n; i++)
- {
- if (!(strcmp(A[i].date, d)) )
- {
- sum+=A[i].summ;
- }
- }
- cout << "Total payment of this day = " << sum << endl;
- }
- void NoPay(Payment* A, int n)
- {
- bool month [12];
- for (int i = 0; i<12; i++)
- month[i] = false;
- char* num = new char [3];
- num[2] = 0;
- int m = 0;
- for (int i=0; i<n; i++)
- {
- num[0]=A[i].date[3];
- num[1]=A[i].date[4];
- m = atoi(num);
- month[m-1] = true;
- }
- delete[] num;
- cout << endl << "There were no payments in monthes: " << endl;
- for (int i = 0; i<12; i++)
- {
- if (!month[i])
- {
- switch (i){
- case 0:
- cout << "January; " << endl;
- break;
- case 1:
- cout << "February " << endl;
- break;
- case 2:
- cout << "March; " << endl;
- break;
- case 3:
- cout << "April; " << endl;
- break;
- case 4:
- cout << "May; " << endl;
- break;
- case 5:
- cout << "June; " << endl;
- break;
- case 6:
- cout << "July; " << endl;
- break;
- case 7:
- cout << "August; " << endl;
- break;
- case 8:
- cout << "September; " << endl;
- break;
- case 9:
- cout << "October; " << endl;
- break;
- case 10:
- cout << "November; " << endl;
- break;
- case 11:
- cout << "December; " << endl;
- break;
- }
- }
- }
- }
- void main ()
- {
- Payment* Massiv = 0;
- int n = 0, a;
- cout << "How many strings will be?" << endl;
- cin >> n;
- cin.ignore(256,'\n');
- Massiv = Init(n);
- DataInput(Massiv, n);
- system("cls");
- DataPrint(Massiv, n);
- cout << "Enter the 1st letter of surname : ";
- char FirstLetter;
- cin >> FirstLetter;
- if (cin.peek() == '\n')
- cin.ignore();
- FindPeople(Massiv, n, FirstLetter);
- cout << "You are looking for a payment more than : ";
- int Pay;
- cin >> Pay;
- cin.ignore();
- FindPay(Massiv, n, Pay);
- cout << "Enter date (dd.mm.yy) : ";
- char* date = new char [9];
- cin.getline(date,9);
- TotalPay(Massiv, n, date);
- NoPay(Massiv, n);
- Delete(Massiv, n);
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement