enum Answer
{
    yes, no, maybe
};
 
enum Figurka
{
    jezdec,
    strelec,
    dama,
    kral
};
#include <iostream>
using namespace std;
 
struct Nevim {
    string otazka;
    string odpoved;
    bool jistota;
};
 
const int limit = 100;
int pocet = 0;
Nevim tabulka[limit];
 
void print()
{
    for (int i = 0; i < pocet; i++)
    {
        cout << i << ".) ";
        cout << tabulka[i].otazka << " --> ";
        cout << tabulka[i].odpoved << " : ";
        if (tabulka[i].jistota)
            cout << "jsem si jist" << endl;
        else
            cout << "nejsem si jist" << endl;
    }
}
 
void pridej(string otazka, string odp, bool jistota)
{
    if (pocet < limit)
    {
        tabulka[pocet].otazka = otazka;
        tabulka[pocet].odpoved = odp;
        tabulka[pocet].jistota = jistota;
        pocet++;
    }
}
 
void vkladani(string ot, string odp, bool jist)
{
    if (pocet < limit)
    {
        for (int i = pocet-1; i >= 0 ; i--)
        {
            tabulka[i + 1] = tabulka[i];
        }
        tabulka[0].otazka = ot;
        tabulka[0].odpoved = odp;
        tabulka[0].jistota = jist;
        pocet++;
    }
}
 
void vlozeni(int inx, string ot, string odp, bool jist)
{
    if (pocet < limit && inx >= 0 && inx <= pocet)
    {
        for (int i = pocet - 1; i >= inx; i--)
        {
            tabulka[i + 1] = tabulka[i];
        }
        tabulka[inx].otazka = ot;
        tabulka[inx].odpoved = odp;
        tabulka[inx].jistota = jist;
        pocet++;
    }
}
 
void hledej(string od)
{
    cout << "Nasli jste " << od << " ? " << endl;
    bool nasel = false;
    int i = 0;
    while (i < pocet && ! nasel) {
 
        if (tabulka[i].odpoved == od && tabulka[i].jistota) {
            cout << tabulka[i].otazka << endl;
            nasel = true;
        }
        i++;
    }
    if (!nasel)
        cout << "Nenasli" << endl;
    else
        cout << "Nasli s indexem " << i-1 << endl;
}
 
void prepis(string ot, string odp)
{
    int i = 0;
    while (i < pocet && tabulka[i].otazka != ot) i++;
 
    if (i < pocet)
    {
        tabulka[i].odpoved = odp;
        tabulka[i].jistota = true;
    }
}
 
int main()
{
    pridej("1+1=", "dva", true);
    pridej("3+2=", "dva", false);
    pridej("3+5=", "dva", false);
    pridej("3-1=", "dva", true);
    print();
    cout << endl;
    vkladani("5+4=", "sedm", false);
    vlozeni(2, "5+3=", "osm", true);
    print();
    cout << endl;
    vlozeni(5, "5+4=", "devet", true);
    prepis ("3+2=", "pet");
    print();
    hledej("dva");
    hledej("tri");
}
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
 
struct Item
{
    string name;
    int r, g, b;
};
 
const int Max = 100;
int cnt; // pocet polozek
Item tab [Max]; // tabulka obsahujici polozky
 
void add(string s, int r0, int g0, int b0)
{
    if (cnt < Max)
    {
        tab[cnt].name = s;
        tab[cnt].r = r0;
        tab[cnt].g = g0;
        tab[cnt].b = b0;
        cnt++;
    }
}
 
void sort()
{
    bool ok;
    do
    {
        ok = true;
        for (int i = 0; i < cnt - 1; i++) // porovnat tab[i] a tab[i+1]
        {
            /*
            Item & x = tab[i];
            Item & y = tab[i+1];
 
            bool vetsi;
            if (x.r > y.r) vetsi = true;
            else if (x.r < y.r) vetsi = false;
            else if (x.g > y.g) vetsi = true;
            else if (x.g < y.g) vetsi = false;
            else vetsi = x.b > y.b;
 
            if (vetsi)
            */
            if (tab[i].name > tab[i+1].name)
            {
                ok = false;
                Item tmp = tab[i];
                tab[i] = tab[i + 1];
                tab[i + 1] = tmp;
            }
        }
    } while (ok == false);
}
 
#include <fstream>
void print(ostream & out)
{
    out << "<html>" << endl;
    out << "   <body>" << endl;
    out << "      <ul>" << endl;
    for (int i = 0; i < cnt; i++)
    {
        out << "         <li";
        out << " style=" << '"' << "color:rgb(";
        out << tab[i].r << "," << tab[i].g << "," << tab[i].b;
        out << ")" << '"';
        out << ">";
        out << tab[i].name;
        out << "</li>" << endl;
    }
    out << "      </ul>" << endl;
    out << "   </body>" << endl;
    out << "</html>" << endl;
}
 
/*
    print (cout);
    ofstream f ("abc.html");
    print(f);
    f.close();
*/
 
int main()
{
    cnt = 0;
 
    Item p;
    p.name = "cervena";
    p.r = 255;
    p.g = 0;
    p.b = 0;
    tab[0] = p;
    cnt++;
 
    tab[1].name = "modra";
    tab[1].r = 0;
    tab[1].g = 0;
    tab[1].b = 255;
    cnt++;
 
    add("zelena", 0, 255, 0);
    add("zluta", 255, 200, 0);
    add("oranzova", 255, 144, 0);
    sort();
 
    print (cout);
    ofstream f ("abc.html");
    print(f);
    f.close();
 
    cout << "O.K." << endl;
}
 
// <li style = "color:rgb(255,0,0)">cervena< / li>
 
struct2019.txt · Last modified: 2019/10/29 13:13 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki