Tvary
- Založte nový projekt - File - New - Project ...
Win32 Conzole Appplication ...
pojmenujte Tvary a uložte do svého adresáře
- Přidejte novou třídu tvar
Solution Explorer - Tvary - kontextové menu - Add - Class.. - Add - C++ Class
- Vložte kód do třídy tvar
#pragma once
class tvar
{
protected:
int a;
public:
tvar::tvar(){};
tvar::tvar(int _a): a(_a){}
int tvar::get_a(){ return a;};
void tvar::set_a(int _a){ a = _a;};
virtual void Kresli(){};
};
- Přidejte novou třídu ctverec
#pragma once
#include "tvar.h"
#include <string>
class ctverec : public tvar
{
public:
virtual void Kresli()
{
for(int r = 0; r < a; r++)
{
for(int s = 0; s < a; s++)
printf("*");
printf( "\n" );
}
}
int get_a(){ return a;};
void set_a(int _a){ a = _a;};
ctverec(int _a) : tvar(_a){};
ctverec(){};
};
- Přidejte novou třídu trojuhelnik
class trojuhelnik : public tvar
{
public:
virtual void Kresli() override
{
for(int r = 0; r < a; r++)
{
for(int s = 0; s < r; s++)
printf("*");
printf( "\n" );
}
}
int get_a(){ return a;};
void set_a(int _a){ a = _a;};
trojuhelnik(int _a) : tvar(_a){};
trojuhelnik(){};
};
- V metodě main souboru Tvary.cpp vytvořte trojuhelnik a ctverec
#include "stdafx.h"
#include "ctverec.h"
#include "trojuhelnik.h"
void main()
{
ctverec c1;
c1.set_a(5);
c1.Kresli();
trojuhelnik t1;
t1.set_a(10);
t1.Kresli();
system ("pause");
}
- Vytvořte diagram tříd
|