MECH 215 Study Guide - Final Guide: Johann Bernoulli, Call Graph, Stack Overflow

81 views12 pages
1
Question 1: [20 points]
A brief, yet interesting history of logarithms for those of you who are interested:
“Logarithms were invented independently by John Napier (Figure 1), a Scotsman, and by Joost
Burgi, a Swiss. The logarithms which they invented differed from each other and from the com-
mon and natural logarithms now in use. Napier’s logarithms were published in 1614; Burgi’s log-
arithms were published in 1620. The objective of both men was to simplify mathematical
calculations. Napier’s approach was algebraic and Burgi’s approach was geometric. Neither men
had a concept of a logarithmic base. Napier defined logarithms as a ratio of two distances in a geo-
metric form, as opposed to the current definition of logarithms as exponents. The possibility of
defining logarithms as exponents was recognized by John Wallis in 1685 and by Johann Bernoulli
in 1694.1
Figure 1: Johnny Napier.2
For this question, you will be writing a C++ function which will compute the integer
logKeith (Mick), which is defined to be the smallest integer (call it Charlie) such that:
Keith Charlie >= Mick.
Note that the numbers Keith,Mick and Charlie are all positive integer quantities. Mick is
assumed to be greater than 0.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in
2
The following table gives the values of the integer logKeith(Mick) for several values of the base
Keith and for several values of Mick.
You must use the following function prototype:
int integer_log(int keith, int mick )
// keith = base , mick = x
//
// find the smallest integer charlie such that
//
Table 1: Some Integer logarithms for 3 different bases
Mick log10(Mick) log2(Mick) log3(Mick)
1000
2111
3121
4122
5132
6132
7132
8132
9142
10143
11243
12243
13243
14243
15243
16243
etc. etc. etc. etc.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in
3
// charlie
// keith >= mick
Use only awhile statement, the multiplication arithmetic operator, the addition operator and any
initialization of variables which may be required, as well as the return statement within your
function. In other words, you are not allowed to use the pow(),log(),orlog10() functions
found in the <cmath> library.
The following program typifies how this function would be used within main():
// Author: Ted Obuchowicz
// April 21, 2009
// unsigned binary integer log (x) program
// y
// using function
#include <iostream>
#include <string>
using namespace std;
int integer_log(int , int );
int main()
{
int x; // we restrict x to be greater than 0
int base;
cout << "Please enter the value x you wish to compute the integer log of " ;
cin >> x;
cout << "Please enter the base of the logarithm " ;
cin >> base;
cout << "The answer is: " << integer_log(base, x) << endl;
return 0;
}
Hint: keith 0= 1
keith 1 = keith = 1 * keith
keith 2 = keith * keith = 1 * keith * keith
keith 3 = keith * keith * keith = 1 * keith * keith * keith
keith mick = keith * keith * keith * ... * keith ( keith multiplied by itself mick times)
Another Hint: Figure out how many times you have to multiply 1 by Keith in order for it
to become bigger or equal to Mick.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers