Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78976590
ch-05-FunctionOverloading.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 24, 02:17
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Aug 26, 02:17 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
20130625
Attached To
R9360 PCSC_git
ch-05-FunctionOverloading.cpp
View Options
/*
* ch-05-FunctionOverloading.cpp
*
* Function Overloading
*
* Created on: Oct 5, 2012
* Author: Simone Deparis <simone.deparis@epfl.ch>
*/
#include <iostream>
void
Multiply
(
double
scalar
,
double
*
u
,
double
*
v
,
int
n
);
void
Multiply
(
double
scalar
,
double
**
A
,
double
**
B
,
int
n
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
n
=
2
;
double
*
u
=
new
double
[
n
];
double
*
v
=
new
double
[
n
];
double
**
A
=
new
double
*
[
n
];
double
**
B
=
new
double
*
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
A
[
i
]
=
new
double
[
n
];
B
[
i
]
=
new
double
[
n
];
}
u
[
0
]
=
-
8.7
;
u
[
1
]
=
3.2
;
A
[
0
][
0
]
=
2.3
;
A
[
0
][
1
]
=
-
7.6
;
A
[
1
][
0
]
=
1.3
;
A
[
1
][
1
]
=
45.3
;
double
s
=
2.3
,
t
=
4.8
;
// vector multiplication
Multiply
(
s
,
u
,
v
,
n
);
// matrix multiplication
Multiply
(
t
,
A
,
B
,
n
);
delete
[]
u
;
delete
[]
v
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
delete
[]
A
[
i
];
delete
[]
B
[
i
];
}
delete
[]
A
;
delete
[]
B
;
return
0
;
}
void
Multiply
(
double
scalar
,
double
*
u
,
double
*
v
,
int
n
)
{
// v = scalar*u (scalar by vector)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
v
[
i
]
=
scalar
*
u
[
i
];
}
}
void
Multiply
(
double
scalar
,
double
**
A
,
double
**
B
,
int
n
)
{
// B = scalar*A (scalar by matrix)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
B
[
i
][
j
]
=
scalar
*
A
[
i
][
j
];
}
}
}
Event Timeline
Log In to Comment