Starting from:

$25

CS160- Assignement 8 Solved

·    Orientation

Cache- a collection of items of the same type stored in a hidden or inaccessible place.

Compiler- a program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer.

Interpreter- a program that can analyze and execute a program line by line.

Stack- a stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed.

Heap- a heap is a specialized tree-based data structure which is essentially an almost complete tree that satisfies the heap property: in a max heap, for any given node C, if P is a parent

 

·    Understanding the problem

For the first program I need I will need to create a list of names that I’ll get by the input of the user. Then I’d print how many occurrences the letters in all the names happen.

For the second program I need to create two lists of numbers which I’ll get from the user. Then I’ll have five functions that A, return true or false if the lists are the same length. B return the sum of a list. C return the average of a list. D return true or false if the sum of two lists are different. E return the common numbers between two lists.

 

 

 

 

·    Devise a plan



This flow chart is the bare bones of what my program will look like.

 

After the sum and average function is chosen by the user I’ll ask the user to choose which list to use. I forgot to add that in the flow chart. The rest of the functions will have to use both lists.

 

At the start of main I’ll have the user choose whether to make a list of names or two lists of numbers, this will separate the two programs. I’ll do this by having a variable equal the users input and next I’ll have an if statement to check if the input equal “names”. Then an elif statement to see if the input equal “numbers”. That’s how I’ll have the user decide between modes.

 

Also whenever I ask the user for input I’ll have an else statement or if statement to take care of incorrect input.

 

Then to account for the occurrence of letters I’ll have the one list of names generated by the user. Then another list that’s empty and I’ll use that has the number of occurrences. I’ll have the empty list be filled with the letter then number of occurrences so. I’ll have the character of the first element of the name_list be compared to every character of the first element of the list and the next and so on. For every occurrence I’ll add 1. At the end of the list the character will be appended to the new list and then the occurrence will be appended to the list. Then for the next letter of the first element it checks the new list of all variable%2 positions (because that’s where all the letters will be) to make sure that letter hasn’t been checked already. Then after that’s all complete I’ll print that to the screen.

 

Then for the numbers I’ll make two lists and have the user input the values and I’ll use the check for int function we made during Lab to check and make sure the inputs are valid integers. Then if all the inputs are good I’ll ask the user to choose which function they want to do. One of the five we were told to do. And then when the user enters the number corresponding to the function choice it should give the correct answer of whatever the function was supposed to do.

 

 

 

 

 

 

 

 

·    Looking back

·      Input
Expected
Actual meet expectation
FOR NAME LIST
 
 
Enters any combination of letters
Will add that to the list as a name
Yes
Enters any combination of letters and numbers
Will say I entered an incorrect name
Yes

 
Enter a space then letters
Will say I entered an incorrect name
Yes
Enter just numbers
Will say I entered an incorrect name
Yes
FOR NUMBER LISTS
 
 
Enter anything and it’d be added to the list, initially
Will add it to the number 1 list
Yes
Enter “stop”
Will say okay now enter values for the second list
Yes
Enter anything and it’d be added to the list, initially
Will add it to the number 2 list
Yes
Enters 1 for function#1
Returns true or false base on the lengths of each list
Yes
Enters 2 for function#2
Will ask which list to use
Yes
Enters 1 for list 1
Will test the length of list 1
Yes
Enters 2 for list 2
Will test the length of list 2
Yes
Enters 3 for function#3
Will ask which list to use
Yes
Enters 1 for list 1
Will return the average of list 1
Yes
Enters 2 for list 2
Will return the average of list 2
Yes
Enters 4 for function#4
Will tests to see if the sums of list1 and list2 are different
Yes
Enters 5 for function#5
Will return the common numbers between the lists
Yes
 

 

 

 

More products