maturita-ico

//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: firma.cpp
* Author: ucitel
*
* Created on 22. února 2018, 11:48
*/

#include "firma.hpp"
#define DEFAULT_ICO "12345678"
#include <iostream>

//konstruktor bez par.
firma::firma() {
this->ICO = DEFAULT_ICO;
}

//kopirovaci konstruktor
firma::firma(const firma& orig) {
this->ICO = orig.getICO();
}

//konstruktor s par.

firma::firma(const std::string ICO){
if(!setICO(ICO)){
this->ICO = DEFAULT_ICO;
}
}

//destruktor

firma::~firma() {
}

//ziskani ica
std::string firma::getICO()const{
return this->ICO;
}

//zadani ica
bool firma::setICO(const std::string ICO){
if(kontrola(ICO)){
this->ICO = ICO;
return true;
}
else
return false;
}

//kontrola ica

bool firma::kontrola(const std::string ICO) const{
int soucet = 0;
int vaha = 8;
if(ICO.length()!=8){
return false;
}
//Kontrola na cifry
for(int i=0; i<ICO.length(); i++){
if(ICO[i]<'0'|| ICO[i]>'9'){
return false;
}
}

for(int i=0; i < 7; i++){
soucet += std::stoi(ICO.substr(i,1))*vaha;
vaha--;
}

int zbytek = soucet%11;
int kc = ((11-zbytek)%10)%10;

if(kc==std::stoi(ICO.substr(7,1)))
return true;
else
return false;
}

//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: firma.hpp
* Author: ucitel
*
* Created on 22. února 2018, 11:48
*/

#ifndef FIRMA_HPP
#define FIRMA_HPP
#include <string>

class firma {
public:
firma();
firma(const firma &);
firma(const std::string);
virtual ~firma();
std::string getICO()const;
bool setICO(const std::string);
private:
std::string ICO;
bool kontrola(const std::string)const;

};

#endif /* FIRMA_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: ucitel
*
* Created on 22. února 2018, 11:48
*/

#include <cstdlib>
#include "firma.hpp"
#include <iostream>

using std::string;
using std::cout;
using std::cin;
using std::endl;

/*
*
*/
int main(int argc, char** argv) {

firma f1;
firma f2(f1);
firma strojka("47831121");
string ICO;
cout<<"Objekt vytvoreny kontruktorem bez parametru."<<endl;
cout<<"ICO:"<<f1.getICO()<<endl;
cout<<"Objekt vytvoren kopirovacim konstruktorem."<<endl;
cout<<"ICO:"<<f2.getICO()<<endl;
cout<<"Objekt vytvoreny kontruktorem s parametrem."<<endl;
cout<<"ICO:"<<strojka.getICO()<<endl;
do{
cout<<"Zadej ICO:";
cin>>ICO;
if(f1.setICO(ICO)){
cout<<"ICO po zmene:"<<f1.getICO()<<endl;
}
else
cout<<"Chybne ICO"<<endl;
}while(1);
return 0;
}














//view
{* Latte template *}

{block content}
<h2>{$row->title}</h2>
<p>{$row->content}</p>
<hr>
<p>Datum vydání: <b>{$row->date|date:'j. n. Y'}</b>,
rubrika: <i>{$row->category}</i></p>
<p><a n:href="News:default">Seznam zpráv</a></p>









//update+insert
{* Latte template *}

{block content}
<h2>Editace zprávy</h2>
{control newsForm}






//default
{* Latte template *}

{block content}
<h2>Seznam zpráv</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th><a n:href="News:default 'title'">Titulek</a></th>
<th><a n:href="News:default 'date DESC'">Datum vydání</a></th>
<th><a n:href="News:default 'category'">Rubrika</a></th>
<th><a n:href="News:default 'published DESC'">Publikováno</a></th>
<th>Akce</th>
</tr>
</thead>
<tbody>
{foreach $data as $row}
<tr>
<td><a n:href="News:view $row->id_news">{$row->title}</a></td>
<td>{$row->date|date:'%d.%m.%Y'}</td>
<td>{$row->category|upper}</td>
<td>{$row->published ? 'ANO' : 'NE'}</td>
<td><a n:href="News:update $row->id_news" class="btn btn-success">Editace</a>
<a n:href="News:delete $row->id_news" class="btn btn-danger">Smazat</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
<p><a n:href="News:insert" class="btn btn-primary">Nový</a></p>





//newsprsnt
<?php

namespace App\Presenters;

use Nette;
use App\Model;
use Nette\Application\UI\Form;

class NewsPresenter extends BasePresenter {
private $database;

function __construct(\Nette\Database\Context $database) {
$this->database = $database;
}


public function renderDefault($order='title') {
$this->template->data =
$this->database->table('news')
->order($order)
->fetchAll();
}

public function renderView($id) {
$this->template->row = $this->database->table('news')->get($id);
}

public function actionDelete($id) {
$this->database->table('news')
->where('id_news',$id)
->delete();
$this->flashMessage("Zpráva byla smazána");
$this->redirect("News:default");
}

public function renderInsert() {
}

public function renderUpdate($id) {
$data = $this->database->table('news')->get($id);
if (!$data) {
$this->error('Zpráva nebyla nalezen');
}
$this['newsForm']->setDefaults($data->toArray());
}

protected function createComponentNewsForm()
{
$form = new Form;
$form->addText('title', 'Titulek:')
->setRequired(TRUE);
$form->addTextArea('content', 'Obsah:', 50, 5);
$form->addText('date','Datum:')
->setRequired(TRUE);
$items = array(1=>"Ano",0=>"Ne");
$form->addRadioList('published', 'Publikováno', $items);
$category = array("hardware"=>"Hardware",
"software"=>"Software",
"networking"=>"Sítě",
"programming"=>"Programování");
$form->addSelect('category', 'Kategorie', $category);
$form->addSubmit('submit', 'Potvrdit');
$form->onSuccess[] = [$this, 'newsFormSucceeded'];
return $form;
}

// volá se po úspěšném odeslání formuláře
public function newsFormSucceeded(Form $form, $values)
{
$id = $this->getParameter('id');
if ($id) {
$news = $this->database->table('news')->get($id);
$news->update($values);
$this->flashMessage('Zpráva byla úspěšně aktualizována.');
} else {
$this->database->table('news')->insert($values);
$this->flashMessage('Zpráva byla úspěšně vložena.');
}
$this->redirect('News:default');
}

}


//hmpgprs

class HomepagePresenter extends BasePresenter
{

public function renderDefault()
{
$this->template->anyVariable = 'any value';
}

}


//layout
{**
* @param string $basePath web base path
* @param array $flashes flash messages
*}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Sandbox</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{$basePath}/css/bootstrap.min.css">
<link rel="stylesheet" href="{$basePath}/css/style.css">
{block head}{/block}
</head>

<body>
<header class="jumbotron">
<h1 class="text-center">Informator</h1>
</header>
<main class="container">
<div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>

{include content}
</main>
<footer>
<hr>
<p>&copy; 2018 - Marek Lučný</p>
</footer>

{block scripts}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="{$basePath}/js/bootstrap.min.js"></script>
<script src="https://nette.github.io/resources/js/netteForms.min.js"></script>
<script src="{$basePath}/js/main.js"></script>
{/block}
</body>
</html>



Last edited on
Hello maturita2,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

This is going to take awhile to figure out what you have here and with no reas question I have no idea what you want or need.

Andy
Topic archived. No new replies allowed.