Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Gruppe04
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frederik Simonsen
Gruppe04
Commits
12928667
Commit
12928667
authored
3 years ago
by
Sondre
Browse files
Options
Downloads
Patches
Plain Diff
laster opp les data
parent
34e15144
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
LesData3.cpp
+86
-0
86 additions, 0 deletions
LesData3.cpp
LesData3.h
+23
-0
23 additions, 0 deletions
LesData3.h
with
109 additions
and
0 deletions
LesData3.cpp
0 → 100644
+
86
−
0
View file @
12928667
/**
* Enkel verktykasse for lese: tegn og tall.
*
* FULLSTENDIG IDENTISK til 'LesData2.h' bare at adskilt
* funksjonenes DEKLARASJON og DEFINISJON (som er p DENNE filen).
*
* @file LesData3.CPP
* @author Frode Haug, NTNU
*/
#include
<iostream>
// cin, cout
#include
<iomanip>
// setprecision
#include
<cctype>
// toupper
#include
<cstdlib>
// atoi, atof
#include
"LesData3.h"
// Prototypene for denne filens innhold
/**
* Leser og returnerer ett (upcaset) tegn.
*
* @param t - Ledetekst til brukeren nr ber om ett tegn
*
* @return Ett (upcaset) tegn.
*/
char
lesChar
(
const
char
*
t
)
{
char
tegn
;
std
::
cout
<<
t
<<
": "
;
std
::
cin
>>
tegn
;
std
::
cin
.
ignore
(
MAXCHAR
,
'\n'
);
return
(
toupper
(
tegn
));
}
/**
* Leser og returnerer et flyttall mellom to gitte grenser.
*
* @param t - Ledetekst til brukeren nr ber om input/et tall
* @param min - Minimum for innlest og godtatt tallverdi
* @param max - Maksimum for innlest og godtatt tallverdi
*
* @return Godtatt verdi i intervallet 'min' - 'max'
*/
float
lesFloat
(
const
char
*
t
,
const
float
min
,
const
float
max
)
{
char
buffer
[
MAXCHAR
]
=
""
;
float
tall
=
0.0F
;
bool
feil
=
false
;
do
{
feil
=
false
;
std
::
cout
<<
std
::
fixed
<<
std
::
showpoint
<<
std
::
setprecision
(
2
);
std
::
cout
<<
t
<<
" ("
<<
min
<<
" - "
<<
max
<<
"): "
;
std
::
cin
.
getline
(
buffer
,
MAXCHAR
);
tall
=
static_cast
<
float
>
(
atof
(
buffer
));
if
(
tall
==
0
&&
buffer
[
0
]
!=
'0'
)
{
feil
=
true
;
std
::
cout
<<
"
\n
ERROR: Not a float
\n\n
"
;
}
}
while
(
feil
||
tall
<
min
||
tall
>
max
);
return
tall
;
}
/**
* Leser og returnerer et heltall mellom to gitte grenser.
*
* @param t - Ledetekst til brukeren nr ber om input/et tall
* @param min - Minimum for innlest og godtatt tallverdi
* @param max - Maksimum for innlest og godtatt tallverdi
*
* @return Godtatt verdi i intervallet 'min' - 'max'
*/
int
lesInt
(
const
char
*
t
,
const
int
min
,
const
int
max
)
{
char
buffer
[
MAXCHAR
]
=
""
;
int
tall
=
0
;
bool
feil
=
false
;
do
{
feil
=
false
;
std
::
cout
<<
t
<<
" ("
<<
min
<<
" - "
<<
max
<<
"): "
;
std
::
cin
.
getline
(
buffer
,
MAXCHAR
);
tall
=
atoi
(
buffer
);
if
(
tall
==
0
&&
buffer
[
0
]
!=
'0'
)
{
feil
=
true
;
std
::
cout
<<
"
\n
ERROR: Not an integer
\n\n
"
;
}
}
while
(
feil
||
tall
<
min
||
tall
>
max
);
return
tall
;
}
This diff is collapsed.
Click to expand it.
LesData3.h
0 → 100644
+
23
−
0
View file @
12928667
/**
* Enkel verktykasse for lese: tegn og tall.
*
* FULLSTENDIG IDENTISK til 'LesData2.h' bare at adskilt
* funksjonenes DEKLARASJON (som er p DENNE filen) og DEFINISJON.
*
* @file LesData3.H
* @author Frode Haug, NTNU
*/
#ifndef __LESDATA3_H
#define __LESDATA3_H
const
int
MAXCHAR
=
200
;
// Max.tegn i input-buffer.
char
lesChar
(
const
char
*
t
);
float
lesFloat
(
const
char
*
t
,
const
float
min
,
const
float
max
);
int
lesInt
(
const
char
*
t
,
const
int
min
,
const
int
max
);
#endif
\ No newline at end of file
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