,   CyberForum.ru

: , , - C++

C++ ++ http://www.cyberforum.ru/cpp-beginners/thread566134.html
( ) for while. .
C++ : , , "" . , , "" . http://www.cyberforum.ru/cpp-beginners/thread566125.html
Matrix C++
!! : Matrix, , 1: - , 2: - . ((( -- ! : Matrix: #include <iostream> #include <stdio.h> #include...
C++
, M?
C++ gpss http://www.cyberforum.ru/cpp-beginners/thread566092.html
. , . 1 . 2 . ...
C++ . , ... VLC, ! ( - ): double porog=80; double TekProch=0; int temper=0; double pro=0; double prevpro = 0;

-==-
FAQ
06.05.2012, 17:25     : , ,

: , , . "", .
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <fstream>
#include <clocale>
#include <string>
using namespace std;
 
struct BOOK
{
    string author;
    string bookname;
    int year;
};
 
bool getStruct(ifstream &ifs, BOOK &pBOOK);//Âåð*¸ò ÈÑÒÈÍÀ åñëè óñïåø*î è*èöè*ëèçèðóåì
//ñòðóêòóðó pBOOK èç ô*éëîâîãî ïîòîê* ifstream
void outStruct(BOOK pBOOK);//Ïå÷*ò*åò ïîëÿ ñòðóêòóðû ** ýêð**å
void swpStruct(BOOK &pLEFT, BOOK &pRIGHT);//Îáìå*èâ*åò ñîäåðæèìîå ñòðóêòóð pLEFT pRIGHT
template <class T>
T * SetMemory(T * ptr, long n);//Âûäåëÿåò ï*ìÿòü â n ýëåìå*òîâ 
 
int main()
{
    system("chcp 1251");
    //setlocale(LC_ALL,"RUS");
    int i, j, n = 0;//Áóäåò ñîäåðæ*òü â ñåáå ÷èñëî ñòðóêòóð
    BOOK * list = NULL;//Óê*ç*òåëü ** **ø ì*ññèâ ñòðóêòóð èç ô*éë*
    ifstream ifs("data.txt");//Ïðîáóåì îòêðûòü ô*éë äëÿ ÷òå*èÿ
    if(!ifs.is_open())
        cout<<"Îøèáê* îòêðûòèÿ ô*éë* ä***ûõ\n";//Óïñ ñëó÷èëñÿ êîñÿê, 
        //ëèáî ô*éë ç**ÿò äðóãèì ïðèëîæå*èåì ëèáî åãî *åò â òåêóùåì ê*ò*ëîãå ñîâñåì
    else
    {
        if(!(ifs>>n))
            cout<<"Îøèáê* ÷òå*èÿ ÷èñë* ñòðóêòóð\n";
        else
        if((list = SetMemory(list, n)))
        for(i = 0; i < n && !ifs.eof(); i++)
        {
            if(getStruct(ifs,list[i]))
                outStruct(list[i]);
            else
                break;
        }
        ifs.close();
        if(i != n)
            cout<<"Îøèáê* ÷òå*èÿ ì*ññèâ* ñòðóêòóð\n";
        else//Åñëè âñ¸ ñ÷èò*ëè äåë*åì ñîðòèðîâêó ïî ãîäó
        {
            for(i = 0    ; i < n; i++)
            for(j = i + 1; j < n; j++)
            {
                if(list[j].year < list[i].year)
                    swpStruct(list[j], list[i]);
            }
            cout<<"\nÑîðòèðîâ***ûé ì*ññèâ ñòðóêòóð\n";
            //Âûâîäèì ñîðòèðîâ***ûé ì*ññèâ ñòðóêòóð
            for(i = 0; i < n ; i++)
                outStruct(list[i]);
        }
        if(list)
            delete [] list;//×èñòèì ï*ìÿòü
    }
    system("pause");
    return 0;
}
    
bool getStruct(ifstream &ifs, BOOK &pBOOK)
{
    bool bCorrect = false;
    if(ifs>>pBOOK.author)
    if(ifs>>pBOOK.bookname)
    if(ifs>>pBOOK.year)
        bCorrect = true;
    if(!bCorrect)//Åñëè ââîä áûë ñ îøøèáê*ìè - ÷èñòèì ïîòîê
    {
        ifs.clear();
        ifs.sync();
    }
    return bCorrect;
}
 
void outStruct(BOOK pBOOK)
{
    cout<<"Àâòîð    : "<<pBOOK.author<<endl;
    cout<<"Í*çâ**èå : "<<pBOOK.bookname<<endl;
    cout<<"Ãîä èçä**èÿ : "<<pBOOK.year<<endl;
}
 
void swpStruct(BOOK &pLEFT, BOOK &pRIGHT)
{
    BOOK pBUF = pLEFT;
    pLEFT = pRIGHT;
    pRIGHT= pBUF;
}
 
template <class T>
T * SetMemory(T * ptr, long n)
{
    try
    {
        ptr = new T[n];
    }
    catch(bad_alloc &e)
    {
        cout<<"Îøèáê* âûäåëå*èÿ ï*ìÿòè : "<<e.what()<<endl;
        ptr = NULL;
    }
    return ptr;
}

5
1 1 1998
2 2 2005
3 3 1984
4 4 2012
5 5 2001
     : , ,   
 
: 04:48. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru