maturita-auto

//pohlavi
SELECT
prijmeni AS Příjmení,
jmeno AS Jméno,
IF (SUBSTRING(rodne_cislo,3,2) > 12, 'žena', 'muž') AS Pohlaví,
SUBSTRING(rodne_cislo,5,2)-0 AS Den,
IF (SUBSTRING(rodne_cislo,3,2) > 12, SUBSTRING(rodne_cislo,3,2)-50,
SUBSTRING(rodne_cislo,3,2)-0) AS Měsíc,
CONCAT('19',LEFT(rodne_cislo,2)) AS Rok
FROM `osoby`
WHERE rodne_cislo < '900101'
ORDER BY Pohlaví


//datum z rc
SELECT
prijmeni AS Příjmení,
jmeno AS Jméno,
IF( SUBSTRING( rodne_cislo, 3, 2 ) >12, 'žena', 'muž' ) AS Pohlaví,
CONCAT_WS('.',SUBSTRING( rodne_cislo, 5, 2 ) -0,IF( SUBSTRING( rodne_cislo, 3,
2 ) >12, SUBSTRING( rodne_cislo, 3, 2 ) -50, SUBSTRING( rodne_cislo, 3, 2 )
-0 ),CONCAT( '19', LEFT( rodne_cislo, 2 ) )) AS `Datum narození`
FROM `osoby`
WHERE rodne_cislo < '900101'

//
SELECT tridy_trida as `Třída`, SUM(absence) as `Celková absence`,
ROUND(AVG(absence),2) as `Průměrná absence`, MAX(absence) as
`Maximální absence`
FROM studenti
GROUP BY tridy_trida
ORDER BY tridy_trida




//cpp
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/*
* File: Auto.cpp
* Author: ucitel
*
* Created on 13. listopadu 2017, 11:39
*/

#include "Auto.hpp"
#include <cstring>
#include <ctime>

#define SPZ "NO_SPZ"
#define SPOTREBA 0.1
#define ROK_VYROBY 1900
#define DELKA_SPZ 7

Auto::Auto() {
this->spz=new char[DELKA_SPZ+1];
if(this->spz !=0)
strcpy(this->spz, SPZ);
this->spotreba=SPOTREBA;
this->rok=ROK_VYROBY;
}

Auto::Auto(const char* spz, float spotreba, int rok){
this->spz=new char[DELKA_SPZ+1];
if(this->spz !=0){
if(kontrolaSPZ(spz))
strcpy(this->spz, spz);
else
strcpy(this->spz, SPZ);
}
if(kontrolaSpotreby(spotreba))
this->spotreba=spotreba;
else
this->spotreba=SPOTREBA;
if(kontrolaRoku(rok))
this->rok=rok;
else
this->rok=ROK_VYROBY;
}

Auto::Auto(const Auto & orig) {
this->spz=new char[DELKA_SPZ+1];
if(this->spz !=0)
strcpy(this->spz, orig.getSpz());
this->spotreba=orig.getSpotreba();
this->rok=orig.getRok();
}

Auto::~Auto() {
if(this->spz !=0){
delete[]this->spz;
this->spz=0;
}
}

char* Auto::getSpz()const {
return this->spz;
}

float Auto::getSpotreba() const{
return this->spotreba;
}

int Auto::getRok() const{
return this->rok;
}

int Auto::sysRok() const{
time_t rawtime;
struct tm * timeinfo;

time (&rawtime);
timeinfo = localtime (&rawtime);
return timeinfo->tm_year+1900;
}

int Auto::stariVozu()const {
return sysRok()-this->rok;
}
bool Auto::kontrolaRoku(int rok) const{
if(rok>ROK_VYROBY && rok<=sysRok())
return true;
else
return false;
}

bool Auto::kontrolaSpotreby(float spotreba) const{
if(spotreba>0)
return true;
else
return false;
}
bool Auto::setSpotreba(float spotreba){
if(kontrolaSpotreby(spotreba)){
this->spotreba=spotreba;
return true;
}
return false;
}

bool Auto::setRokVyroby(int rok){
if(kontrolaRoku(rok)){
this->rok=rok;
return true;
}
return false;
}

bool Auto::setSpz(char* spz){
if(kontrolaSPZ(spz)){
strcpy(this->spz, spz);
return true;
}
return false;
}

bool Auto::kontrolaSPZ(const char* spz) const{
if(strlen(spz)<5 || strlen(spz)>7)
return false;
for(int i = 0;i < strlen(spz);i++){
if((spz[i]<'A'||spz[i]>'Z')&&(spz[i]<'0'||spz[i]>'9')
||(spz[i]=='G'|| spz[i]=='O' || spz[i]=='W' || spz[i]=='Q'))
return false;
}
return true;
}
//hpp
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/*
* File: Auto.hpp
* Author: ucitel
*
* Created on 13. listopadu 2017, 11:39
*/

#ifndef AUTO_HPP
#define AUTO_HPP

class Auto {
public:
Auto();
Auto(const Auto &);
Auto(const char*,float, int);
bool setSpz(char *);
bool setSpotreba(float);
bool setRokVyroby(int);
char *getSpz()const;
float getSpotreba()const;
int getRok()const;
int stariVozu()const;
virtual ~Auto();
private:
char *spz;
float spotreba;
int rok;
bool kontrolaSPZ(const char*)const;
int sysRok()const;
bool kontrolaRoku(int)const;
bool kontrolaSpotreby(float)const;
};

#endif /* AUTO_HPP */



//main
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/*
* File: main.cpp
* Author: student
*
* Created on 13. listopadu 2017, 11:39
*/

#include <cstdlib>
#include <cctype>
#include <iostream>
#include "Auto.hpp"

using namespace std;

/*
*
*/
int main(int argc, char** argv) {
Auto a1;
Auto a2(a1);
Auto mojeAuto("3T21098",6.5,1998);
int rokVyroby;
float spotreba;
char spz[50];
cout<<"Objekt vytvoren konstruktorem bez parametru"<<endl;
cout<<"spz: "<<a1.getSpz()<<endl;
cout<<"Spotreba: "<<a1.getSpotreba()<<endl;
cout<<"Rok vyroby: "<<a1.getRok()<<endl;
cout<<"Stari vozu: "<<a1.stariVozu()<<endl;
cout<<"Objekt vytvoren kopirovacim konstruktorem:"<<endl;
cout<<"spz: "<<a2.getSpz()<<endl;
cout<<"Spotreba: "<<a2.getSpotreba()<<endl;
cout<<"Rok vyroby: "<<a2.getRok()<<endl;
cout<<"Stari vozu: "<<a2.stariVozu()<<endl;
cout<<"Objekt vytvoren konstruktorem s parametry"<<endl;
cout<<"spz: "<<mojeAuto.getSpz()<<endl;
cout<<"Spotreba: "<<mojeAuto.getSpotreba()<<endl;
cout<<"Rok vyroby: "<<mojeAuto.getRok()<<endl;
cout<<"Stari vozu: "<<mojeAuto.stariVozu()<<endl;
do {
cout<<"Zadej rok vyroby:";
cin>>rokVyroby;
if(a1.setRokVyroby(rokVyroby))
cout<<"Stari vozu: "<<a1.stariVozu()<<endl;
else
cout<<"Chybne zadany rok vyroby!"<<endl;
cout<<"Zadej spotrebu:";
cin>>spotreba;
if(a1.setSpotreba(spotreba))
cout<<"Spotreba: "<<a1.getSpotreba()<<endl;
else
cout<<"Chybne zadana spotreba!"<<endl;
cout<<"Zadej spz:";
cin>>spz;
if(a1.setSpz(spz))
cout<<"Spz: "<<a1.getSpz()<<endl;
else
cout<<"Chybne zadana spz!"<<endl;
}while(1);
return 0;
}




Last edited on
Topic archived. No new replies allowed.