-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.cpp
More file actions
43 lines (35 loc) · 1.1 KB
/
Copy pathjava.cpp
File metadata and controls
43 lines (35 loc) · 1.1 KB
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
#include "java.h"
Java::Java(std::string name, double price, double cost, Darkness darkness)
: Product{name, price, cost}, _darkness{darkness} { }
Java::Java(std::istream& ist):Product{ist} {
int temp, shot_num;
ist >> temp; ist.ignore();
_darkness = (Darkness)temp;
ist >> temp; ist.ignore();
shot_num = temp;
for(int i = 0;i<shot_num;i++)
{
ist >> temp; ist.ignore();
_shots.push_back((Shot)temp);
}
}
void Java::add_shot(Shot shot) {_shots.push_back(shot);}
void Java::save(std::ostream& ost) {
ost<< "(JAVA)"<<std::endl;
ost << _name << std::endl;
ost << _price << std::endl;
ost << _cost << std::endl;
ost <<(int) _darkness << std::endl;
ost << _shots.size()<<std::endl;
for(int i=0; i <_shots.size();i++)
{
ost <<(int) _shots[i] << std::endl;
}
}
std::string Java::to_string() {
std::string result = Product::to_string() + " (" + darkness_to_string[_darkness]
+ ")";
std::string separator = " with ";
for (auto s : _shots) {result += separator + shot_to_string[s]; separator = ", ";}
return result;
}