Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDIU20
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cpp-programmering
TDIU20
Commits
7bd593c1
Commit
7bd593c1
authored
2 years ago
by
alrap417
Browse files
Options
Downloads
Patches
Plain Diff
message
parent
4229a602
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Uppgift-1-Klockslag/tdiu20-given-files-master/Time.cc
+38
-2
38 additions, 2 deletions
Uppgift-1-Klockslag/tdiu20-given-files-master/Time.cc
Uppgift-1-Klockslag/tdiu20-given-files-master/Time.h
+3
-2
3 additions, 2 deletions
Uppgift-1-Klockslag/tdiu20-given-files-master/Time.h
with
41 additions
and
4 deletions
Uppgift-1-Klockslag/tdiu20-given-files-master/Time.cc
+
38
−
2
View file @
7bd593c1
...
...
@@ -14,6 +14,29 @@ if(check_invalid_format(hour, minute, second)) {
}
}
Time
::
Time
(
std
::
string
const
)
{
Time
t
{
*
this
};
if
(
t
.
size
()
==
8
&&
t
[
2
]
==
':'
&&
t
[
5
]
==
':'
)
{
hour
=
stoi
(
t
.
substr
(
0
,
2
));
minute
=
stoi
(
t
.
substr
(
3
,
2
));
second
=
stoi
(
t
.
substr
(
6
,
2
));
}
if
(
check_invalid_format
(
hour
,
minute
,
second
))
{
throw
invalid_argument
{
"ogiltigt_varde"
};
}
else
{
throw
invalid_argument
{
"ogiltigt_format"
};
}
}
/*
Time::Time(string h, string m, string s) : hour{h}, minute{m}, second{s} {
if(check_invalid_string(hour, minute, second)){
throw invalid_argument{"ogiltig_string"};
}
}*/
int
Time
::
get_second
()
{
//Gets current hour.
return
second
;
...
...
@@ -27,7 +50,16 @@ int Time::get_hour() { //Gets current hour.
return
hour
;
}
/*bool Time::check_invalid_string(int const h, int const m, int const s){
//string fullstring = to_string(get_hour()) + ":" + to_string(get_minute()) + ":" + to_string(get_second());
//string fullstrin = istream
// if (fullstring[6] == "6") {
return true;
} else {
return false;
}
}
*/
bool
Time
::
check_invalid_time
(
int
const
h
,
int
const
m
,
int
const
s
){
if
(
h
>
23
||
h
<
0
||
m
>
59
||
m
<
0
||
s
>
59
||
s
<
0
)
{
...
...
@@ -40,7 +72,7 @@ else
}
}
bool
Time
::
check_invalid_format
(
int
const
h
,
int
const
m
,
int
const
s
){
/*
bool Time::check_invalid_format(int const h, int const m, int const s){
string fullstring = to_string(get_hour()) + ":" + to_string(get_minute()) + ":" + to_string(get_second());
if (fullstring.size() > 8) {
return true;
...
...
@@ -130,6 +162,7 @@ bool Time::is_am() {
return false;
}
}
*/
string
Time
::
to_string
(
const
int
data
)
{
std
::
ostringstream
os
{};
os
<<
data
;
...
...
@@ -138,3 +171,6 @@ string Time::to_string(const int data) {
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Uppgift-1-Klockslag/tdiu20-given-files-master/Time.h
+
3
−
2
View file @
7bd593c1
...
...
@@ -21,14 +21,14 @@ public:
Time
(
int
h
,
int
m
,
int
s
);
Time
()
:
hour
{
0
},
minute
{
0
},
second
{
0
}
{};
Time
(
bool
text
);
Time
(
string
h
,
string
m
,
string
s
);
Time
(
std
::
string
const
);
int
get_hour
();
int
get_minute
();
int
get_second
();
bool
is_am
();
string
to_string
(
const
int
data
);
//Eget funktion
Time
operator
+
(
int
const
n
)
const
;
Time
operator
++
(
int
);
Time
&
operator
++
();
...
...
@@ -49,6 +49,7 @@ private:
bool
check_invalid_time
(
int
const
h
,
int
const
m
,
int
const
s
);
bool
check_default_time
(
int
const
h
,
int
const
m
,
int
const
s
);
bool
check_invalid_format
(
int
const
h
,
int
const
m
,
int
const
s
);
bool
check_invalid_string
(
int
const
h
,
int
const
m
,
int
const
s
);
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment