26.06.2013, 14:43. Просмотров 769. Ответов 2
Всем доброго времени суток. Задачу задали решить на C++. Не могу довести её до ума. Программа запускается, но некорректно работает, а надо, чтобы работала, как часы на спасской башне.

Если у кого-нибудь есть свободное время, то посмотрите её пожалуйста.
Вот условие: реализовать класс Goods, добавив поле-дату поступления товара на склад (использовать класс Date из задания 29). Реализовать метод, вычисляющий срок хранения товара.
Вот код:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| #include "StdAfx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "locale"
using namespace std;
class date
{
public:
void settime(int g, int m, int d)
{god = g; mes = m; day = d;}
void settime(const date &t);
void Display() const;
int god, mes, day;
};
class goods
{
public:
void setgoods(int n, date d, int c, int s)
{name = n; dat = d; cena = c; sr = s;}
void setgoods(const goods &t);
void Display() const;
int name, cena, sr;
date dat;
};
void goods::setgoods(const goods &t)
{
name = t.name;
dat = t.dat;
cena = t.cena;
sr = t.sr;
}
void goods::Display() const
{
printf("Наименование -", name);
printf("Дата", dat);
printf(" - ", cena);
printf(" ", sr);
}
void date::settime(const date &t)
{
god = t.god;
mes = t.mes;
day = t.day;
}
void date::Display() const
{
cout <<"Дата - "<<this -> god<<"."<<this -> mes<<"."<<this -> day;
}
int main()
{
setlocale(LC_ALL, "Russian");
date t;
goods e;
int g,m,d,zn;
cout << "Введите год - " ; cin >> t.god;
cout << "Введите месяц - "; cin >> t.mes;
cout << "Введите число - "; cin >> t.day;
cout<<"\n";
t.settime(t.god, t.mes, t.day);
e.Display();
cout<<"\n";
getch();
return 0;
} |
|
Вместо смайлов в коде, должно быть так
двоеточие Display() const