Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #pragma once
- #include <iostream>
- #include <fstream>
- #pragma warning(disable:4996)
- using namespace std;
- struct Item {
- char Name[35];
- char myDate[8];
- char Section[10];
- int Count;
- friend ostream &operator<<(ostream& out, const Item & s) {
- out << s.Name << " " << s.myDate << " " << s.Section << " " << s.Count;
- return out;
- }
- friend istream &operator>>(istream& in, Item & s) {
- in.ignore();
- in.getline(s.Name, 100, '\n');
- in >> s.myDate >> s.Section >> s.Count;
- in.ignore();
- return in;
- }
- };
- struct Price {
- char Name[35];
- double pr;
- friend ostream &operator<<(ostream& out, const Price & s) {
- out << s.Name << " " << s.pr;
- return out;
- }
- friend istream &operator>>(istream& in, Price & s) {
- in.ignore();
- in.getline(s.Name, 100, '\n');
- in >> s.pr;
- in.ignore();
- return in;
- }
- };
- struct Med {
- char Name[35];
- char myDate[8];
- char Section[10];
- double pr;
- int Count;
- friend ostream &operator<<(ostream& out, const Med & s) {
- out << s.Name << " " << s.myDate << " " << s.Section << " " << s.pr << " " << s.Count;
- return out;
- }
- friend istream &operator>>(istream& in, Med & s) {
- in.getline(s.Name, 100, '\n');
- in >> s.myDate >> s.Section >> s.pr>>s.Count;
- return in;
- }
- };
- template <class T>
- class MED {
- //char Table_Title[50];
- int count;
- T* M;
- public:
- MED() {
- count = 0;
- M = NULL;
- }
- MED(int _count) {
- count = _count;
- M = new T[count];
- }
- MED(MED & st)
- {
- count = st.count;
- M = new T[count];
- for (int i = 0; i < count; i++)
- M[i] = st.M[i];
- }
- ~MED()
- {
- count = 0;
- delete[]M;
- }
- MED& operator=(const MED &st)
- {
- if (this != &st) {
- count = st.count;
- for (int i = 0; i < count; i++)
- M[i] = st.M[i];
- }
- return *this;
- }
- int GetCount() {
- return count;
- }
- T& operator[](int index)
- {
- return M[index];
- }
- friend ostream& operator<<(ostream& out, const MED<T> & st)
- {
- for (int i = 0; i<st.count; i++)
- out << st.M[i] << endl;
- out << endl;
- return out;
- }
- friend istream& operator>>(istream& out, MED<T> & st)
- {
- for (int i = 0; i<st.count; i++)
- out >> st.M[i];
- return out;
- }
- friend MED<T> operator+(MED<T>& s1, MED<T>& s2) {
- MED<Item> s3(s1.GetCount()+s2.GetCount());
- int k = 0;
- for (int i = 0; i < s1.count; i++) {
- strcpy(s3[k].Name , s1[i].Name);
- strcpy(s3[k].myDate, s1[i].myDate);
- strcpy(s3[k].Section, s1[i].Section);
- s3[k].Count = s1[i].Count;
- k++;
- }
- int lo = 0;
- for (int i = 0; i < s2.GetCount(); i++) {
- for (int j = 0; j < k; j++) {
- if (strcmp(s3[j].Name, s2[i].Name) != 0) {
- lo++;
- }
- if (lo==k) {
- strcpy(s3[k].Name, s2[i].Name);
- strcpy(s3[k].myDate, s2[i].myDate);
- strcpy(s3[k].Section, s2[i].Section);
- s3[k].Count = s2[i].Count;
- k++;
- lo = 0;
- }
- }
- }
- s3.count = k;
- return s3;
- }
- void sort() {
- for (int curSize = this->count; curSize > 1; --curSize) {
- for (int i = 0; i < curSize - 1; ++i) {
- if (strcmp(this->M[i].Name, this->M[i + 1].Name) > 0)
- swap(this->M[i], this->M[i + 1]);
- }
- }
- }
- void sortD() {
- for (int curSize = this->count; curSize > 1; --curSize) {
- for (int i = 0; i < curSize - 1; ++i) {
- if (strcmp(this->M[i].Name, this->M[i + 1].Name) < 0)
- swap(this->M[i], this->M[i + 1]);
- }
- }
- }
- void find(const char* name) {
- for (int i = 0; i < this->count; ++i)
- if (strcmp(this->M[i].Name, name) == 0)
- cout << this->M[i];
- }
- };
- \\\\\\\\\\\\\\\\\\\\\\\\\\\
- #include <fstream>
- #include <iostream>
- #include "func.h"
- #pragma warning(disable:4996)
- using namespace std;
- void main() {
- setlocale(LC_ALL, "RUS");
- ifstream in1("Ob1.txt");
- ifstream in2("Ob2.txt");
- ifstream in3("TOb1.txt");
- ifstream in4("TOb2.txt");
- int n,n1,n2, n3;
- in1 >> n;
- in2 >> n1;
- in1 >> n2;
- in2 >> n3;
- MED<Item> M1(n),M2(n1),M3(n+n1);
- MED<Price> K1(n2), K2(n3), K3(n2+n3);
- in1 >> M1;
- in2 >> M2;
- cout << M1;
- cout << M2;
- cout<< M1 + M2;
- M3 = (M1 + M2);
- cout << M3;
- //in3 >> K1;
- //in4 >> K2;
- /*ofstream out("out.txt");
- in1 >> M1;
- in2 >> M2;
- cout << M1;
- M1.sort();
- cout << M1;
- M1.sortD();
- cout << M1;
- cout << M2;*/
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement