struct ttime {
int hours; int minute; int sec;
};
struct date {
ttime time;
void settime(int, int, int);
void printtime();
};
#include <stdio.h>
#include "date.h"
void date::settime(int h, int m, int s)
{
time.hours = h;
time.minute = m;
time.sec= s;
}
void date::printtime()
{
printf("%i:%i:%i", time.hours, time.minute, time.sec);
}
#include <stdio.h>
#include "date.h"
int main()
{
date a;
a.settime(23,43,10);
a.printtime();
getchar();
return 0;
}
#include <iostream>
#include <stack>
struct IElement
{
virtual ~IElement() {}
};
struct ElementInt: IElement
{
int value = 0;
ElementInt(int v):value(v){}
};
struct ElementFloat: IElement
{
float value;
ElementFloat(int v):value(v){}
};
struct ElementFactory
{
public:
ElementFactory(){}
virtual ~ElementFactory(){}
IElement* createInt(int value) const
{
return new ElementInt(value);
}
IElement* createFloat(float value) const
{
return new ElementInt(value);
}
};
struct Stack
{
public:
Stack(size_t s)
: _size(0)
, _stack(new IElement*[s])
{}
virtual ~Stack()
{
delete[] _stack;
}
IElement* pop()
{
if ( _size==0 )
return nullptr;
return _stack[--_size];
}
void push(IElement* elem)
{
_stack[_size++]=elem;
}
private:
size_t _size;
IElement** _stack;
};
int main()
{
ElementFactory f;
Stack s(3);
s.push( f.createInt(10) );
s.push( f.createFloat(20.0) );
s.push( f.createFloat(30) );
while ( IElement* pval = s.pop() )
{
if ( ElementInt* vint = dynamic_cast<ElementInt*>(pval))
std::cout << vint->value << std::endl;
else if ( ElementFloat* vint =dynamic_cast<ElementFloat*>(pval))
std::cout << vint->value << std::endl;
delete pval;
}
return 0;
}
К тому же в стандартном std:vector весь функционал уже есть
если бы вы опустились до уровня азов и помогли мне)))>
struct ttime {
int hours; int minute; int sec;
};
struct date {
ttime time;
void settime(int, int, int);
void printtime();
};
Так как только вхожу в ООП, сейчас нужно брать классы как структуры.