Вы находитесь на странице: 1из 4

Austin Crofoot, CS120-05, Assignment #9, 12/5/18

Program design sheet:


1.
int fibonacci(int p){
if (p == 0)
{
return 0;
}
else if ( p == 1)
{
return 1;
}
else
{
return (fibonacci(p-1) + fibonacci(p-2));
}
}

double sq(double p, double est, double tol){

if((abs(pow(est,2))-p) <= tol)


{
return est;
}
else
{
return sq(p, (pow(est,2) +p)/(2*est), tol);
}
}
struct list
{
string word;
list *link;
};
2.
void insert(string z) {
list *p = head;
list* temp = (list*) new list;
temp ->word= z;
temp ->link= NULL;

if(head == NULL)
{
head = temp;
}
else{
while( p->link != NULL)
p=p->link;
p->link=temp;
}
}
3.
void smallestVal()
{
list * current;
string small;
int smallest=1000000;
while( current != NULL)
{
if((current->word).length() < smallest)
{
small=current->word;
smallest=(current->word).length();
}
current=current->link;
}cout << "Smallest string is: " << small << endl;
}
4.
void largestVal()
{
list * current;
current = head;
string large;
int largest = 0;
while (current != NULL)
{
if((current->word).length() > largest)
{
large = current-> word;
largest = (current->word).size();
}
current=current->link;
}
cout << "Largest string is: " << large << endl;
}
5.
void finder(string z)
{
list * current;
current=head;
int i=0;
while(current != NULL)
{
if( z == current->word)
{
cout << "The list contains the word " << z << "." << endl;
i++;
}
current=current->link;
}
if (i==0)
{
cout << "The word was not found in the list";
}
}
Sample Calculation Sheet
For Fibonacci sequence example:
Sequence: 123321123
2nd value = 2, 7th value = 1, 9th value = 3
Square Root example:
Square root 169 = 13
Square root 225 = 15
Square root 64 = 8
Programming Log
The total time spent on this program came out to be around 7:30 to 8 hours. A lot of this time was
studying how linked list worked and learning about the chrono library. The chrono library helped me
with the problem I was having with keeping track of the time of the program and the issue I was having
with the clock. The issue I kept having throughout the program design was making mistakes on where
the current node pointed to in the linked list and had to make adjustments. The Fibonacci function
wasn’t too much of a struggle the example in the assignment made it pretty simple to learn and to write
a function for.

Вам также может понравиться