» »

c++ razvščanje po datumu

c++ razvščanje po datumu

pitbull1336 ::

vpisati moram naprimer podatke o 10tih računalnikih
nato pa program izpiše te podatke razvščene po datumu naraščajoče
problem je ker nevem kako bi razvrstil jih po datumu
koda
#include <iostream>
#include <cstdlib>

using namespace std;

struct date
{
       int day, month, year;
};

struct computer
{
       char name[100];
       date buying_date;
       char cpu_speed[100];
       int number_of_cores;
       char size_of_ram[100];
};

computer computers[10];


int main()
{
    cout<<"insert computers\n";
    for ( int i=0; i<10; i++ )
    {
        cout<<"insert name of "<<i+1<<". computer: ";
        cin>>computers[i].name;
        cout<<"inserst date of buying "<<i+1<<". computer: ";
        cin>>computers[i].buying_date.day>>computers[i].buying_date.month>>computers[i].buying_date.year;
        cout<<"insert cpu speed of "<<i+1<<". computer: ";
        cin>>computers[i].cpu_speed;
        cout<<"insert number of cores of "<<i+1<<". cumputer: ";
        cin>>computers[i].number_of_cores;
        cout<<"insert size of ram of "<<i+1<<". computer: ";
        cin>>computers[i].size_of_ram;
    }
    cout<<endl;

    for ( int i=0; i<10; i++ )
    {
        cout<<"name of "<<i+1<<". computer: "<<computers[i].name<<endl<<"date of buying: "<<" "
        <<computers[i].buying_date.day<<"."<<computers[i].buying_date.month<<"."<<computers[i].buying_date.year
        <<endl<<"cpu speed: "<<computers[i].cpu_speed<<", number of cores: "<<computers[i].number_of_cores<<", size of ram: "
        <<computers[i].size_of_ram<<endl<<endl;
    }
    system("pause");
    return 0;
}

_Dormage_ ::

Da bi datume primerjal jih moraš pretvorit. Problem je, da morajo pretvorjeni podatki biti medseboj primerljivi, da bi lahko rekel datum1 > datum2.
Unix timestamp mogoče?
Ali pa KPSK algoritem.

Delpierooo ::

Mogoče lažji način.. iz datuma sestavi številski format YYYYMMDD, ter nato sortiraš dejansko števila. Kasneje prevtoriš nazaj v datum.

Lp

Zgodovina sprememb…



Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[C] Strukture

Oddelek: Programiranje
81058 (640) čuhalev
»

[C] Seznam s poljem

Oddelek: Programiranje
232409 (1889) aceton
»

c++ (sortiranje)

Oddelek: Programiranje
121477 (1340) minghags
»

C strukture, kazalci naloga pomoc

Oddelek: Programiranje
51441 (1336) DavidJ
»

c++ datoteke

Oddelek: Programiranje
464008 (3497) Vesoljc

Več podobnih tem