-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_templates.cpp
More file actions
61 lines (49 loc) · 1.39 KB
/
lab_templates.cpp
File metadata and controls
61 lines (49 loc) · 1.39 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
using namespace std;
/* COMPLETE ME - complete the template definition of the times()
function.
times() should take two parameters (a and b) of the same type and then
return a value of the same type that is equal a and b multiplied together. */
int times( int a, int b )
{
return a * b;
}
float times( float a, float b )
{
return a * b;
}
unsigned int times( unsigned int a, unsigned int b )
{
return a * b;
}
int main()
{
int i = times( 42, -69 );
float f = times( 1.23f, 4.56f );
unsigned int ui = times( std::numeric_limits<int>::max()-1, 2 );
int errors = 0;
if( i != 42*-69 )
{
cout << "int times( int, int ) failed" << endl
<< " expected " << 42*-46 << ", got " << i << endl;
errors++;
}
if( f != 1.23f*4.56f )
{
cout << "float times( float, float ) failed" << endl
<< " expected " << 1.23f*4.56f << ", got " << f << endl;
errors++;
}
if( ui != (std::numeric_limits<int>::max()-1)*2 )
{
cout << "unsigned int times( unsigned int, unsigned int ) failed" << endl
<< " expected " << (std::numeric_limits<int>::max()-1)*2 << ", got " << ui << endl;
errors++;
}
cout << "There were " << errors << " errors" << endl;
return errors;
}