Questions
Can someone explain to me whats happening for every method in this code and the breakdown...

Can someone explain to me whats happening for every method in this code and the breakdown of everything. I added the p2.h file for any reference needed and i need the Implementation of the tree ADT in the p2.h file explained and why it was implemented in that file and not p2.cpp.

p2.cpp

#include 
#include "p2.h"
#include "recursive.h"

using namespace std;

static int sum_helper(list_t list, int total) {
    if(list_isEmpty(list))
    {
                return total;
        }
     else
        return sum_helper(list_rest(list), total + list_first(list));
}
 
int sum(list_t list) {
    return sum_helper(list, 0);
}
 
static int product_helper(list_t list, int total) {
    if(list_isEmpty(list))
    {
                return total;
        }
    else
        return (product_helper(list_rest(list), total * list_first(list)));
}
 
int product(list_t list) {
    return product_helper(list, 1);
}
static int accumulate_helper(list_t list, list_t otherList, int result, int (*fn)(int, int), int identity) {
    if(list_isEmpty(list)) return identity;
    else if(list_isEmpty(otherList))return result;
    else
    {
        result = fn(list_first(otherList), result);
        return accumulate_helper(list, list_rest(otherList), result, fn, identity);
    }
}
 
int accumulate(list_t list, int (*fn)(int, int), int identity) {
    return accumulate_helper(list, list, identity, fn, identity);
}
 
static list_t reverse_helper(list_t list, list_t reverse) {
    if(list_isEmpty(list)) return reverse;
    else return reverse_helper(list_rest(list), list_make(list_first(list), reverse));
}
list_t reverse(list_t list)
{
    return reverse_helper(list, list_make());
}
static list_t append_helper(list_t first, list_t second, list_t reverse_first, list_t result) {
    if(list_isEmpty(first) && list_isEmpty(second)) return list_make();
    else if(list_isEmpty(first))return second;
    else if(list_isEmpty(second))return first;
    else
    {
        if(list_isEmpty(reverse_first))return result;
        else
        {
                 return append_helper(first, second, list_rest(reverse_first), list_make(list_first(reverse_first), result));
        }
    }
}
 
list_t append(list_t first, list_t second) {
    return append_helper(first, second, reverse(first), second);
}
static list_t filter_odd_helper(list_t list, list_t result) {
    if(list_isEmpty(list))return result;
    else
    {
            if (!(list_first(list)%2))
                return filter_odd_helper(list_rest(list), result);
            else return filter_odd_helper(list_rest(list), list_make(list_first(list), result));
    }
}
 
list_t filter_odd(list_t list) {
    return filter_odd_helper(list, list_make());
}
 
static list_t filter_even_helper(list_t list, list_t result) {
    if(list_isEmpty(list))return result;
                else
                {
            if (list_first(list)%2)
                {return filter_even_helper(list_rest(list), result);}
            else 
                {return filter_even_helper(list_rest(list), list_make(list_first(list), result));}
                }
}
 
list_t filter_even(list_t list) {
    return filter_even_helper(list, list_make());
}
 
static list_t filter_helper(list_t list1, list_t otherList, bool (*fn)(int), list_t result) {
    if(list_isEmpty(list1)) return result;
    else if(list_isEmpty(otherList)) return result;
    else if(fn(list_first(otherList)))
    {
          result = list_make(list_first(otherList), result);
          return filter_helper(list1, list_rest(otherList), fn, result);
    }
    else return filter_helper(list1, list_rest(otherList), fn, result);
}
 
list_t filter(list_t list, bool (*fn)(int)) {
    return reverse(filter_helper(list, list, fn, list_make()));
}
 
static list_t rotate_helper(list_t result, unsigned int n){
    if(n == 0 || list_isEmpty(result))return result;
    else return rotate_helper(reverse(list_make(list_first(result), reverse(list_rest(result)))), n-1);
}
 
list_t rotate(list_t list, unsigned int n)
{
    return rotate_helper(list, n);
}
 
static list_t insert_list_helper(list_t inFirst, list_t first, list_t fir1, list_t fir2, list_t second, unsigned int n2, unsigned int n1) {
      if (list_isEmpty(inFirst) || list_isEmpty(second) || n2==0)
     {
      if(n2==0)return append(second, inFirst);
          else return append(inFirst, second);
     } else {
        if (n1>0) 
          {return insert_list_helper(inFirst, list_rest(first), list_make(list_first(first),fir1),list_rest(first),second,n2,n1-1);}
            else
              return append(reverse(fir1), append(second, fir2));
      }
}
 
list_t insert_list(list_t first, list_t second, unsigned int n) {
       return insert_list_helper(first, first, list_make(), list_make(), second, n, n);
}
static list_t chop_helper(list_t numl, unsigned int n) {
      if(list_isEmpty(numl) || n==0) return numl;
      else return chop_helper(list_rest(numl), n-1);
}
list_t chop(list_t l, unsigned int n) {
    return reverse(chop_helper(reverse(l), n));
}
 
int fib(int n) {
    if(n==0) return 0;
    else if (n==1) return 1;
    else return (fib(n-1) + fib(n-2));
}
 
static int fib_tail_helper(int a, int counter, int b, int c) {
    if(a==0)return 0;
    else if(a==1)return 1;
    else
    {
         if(counter
else if(a%2) return c; 
         else return b;
    }
}
 
int fib_tail(int n) {
    if (!(n%2)) return fib_tail_helper(n, 0, 0, 1);
    else return fib_tail_helper(n, 1, 0, 1);
}
 
int tree_sum(tree_t tree)
{
     if(tree_isEmpty(tree)) return 0;
     else if(tree_isEmpty(tree_left(tree))&& tree_isEmpty(tree_right(tree)))return tree_elt(tree);
     else if(tree_isEmpty(tree_left(tree)))return (tree_elt(tree) + tree_sum(tree_right(tree)));
     else if(tree_isEmpty(tree_right(tree)))return (tree_elt(tree) + tree_sum(tree_left(tree)));
     else return(tree_elt(tree) + tree_sum(tree_left(tree)) + tree_sum(tree_right(tree)));
}
 
list_t traversal(tree_t tree)
{
      list_t ord_list = list_make();
 
      if(tree_isEmpty(tree))return ord_list;
                else
                {
           list_t elt = list_make(tree_elt(tree),list_make());
 
           if(!(tree_isEmpty(tree_right(tree))))
                ord_list = append(traversal(tree_right(tree)), elt);
           if(!(tree_isEmpty(tree_left(tree))))
                 ord_list = append(traversal(tree_left(tree)), elt);
 
           return ord_list;
                }
}
bool contained_by(tree_t A, tree_t B)
{
      if(tree_isEmpty(A)) return true;
      else if(!(tree_isEmpty(A) && tree_isEmpty(B))) return false;
                else
                {
            if(list_first(traversal(A)) == list_first(traversal(B)))
                  return contained_by(traversal(A), traversal(B));
            else
                  return(contained_by(tree_right(A), tree_right(B)) && contained_by(tree_left(A), tree_left(B)));
                }
}
 
tree_t insert_tree(int elt, tree_t tree)
{
      if(tree_isEmpty(tree))return tree_make(elt, tree_make(),tree_make());
                else
                {
            if(elt
return tree_make(tree_elt(tree), insert_tree(elt, tree_left(tree)), tree_right(tree)); 
            else
                  return tree_make(tree_elt(tree), tree_left(tree), insert_tree(elt, tree_right(tree)));
                }
}

the implementation in the p2.h file is below.

const unsigned int  tree_node_id = 0x45ee45ee;
const unsigned int  tree_empty_id = 0x56ff56ff;
struct tree_node 
{
    unsigned int       tn_id;    // Are we really a tree_node?
    int                tn_elt;   // This element
    struct tree_node  *tn_left;  // left subtree
    struct tree_node  *tn_right; // right subtree
};
static struct tree_node *
tree_checkValid(tree_t tree)
    // MODIFIES: cerr
    // EFFECTS: assert if tnp does not appear to be a valid tree, 
    //          writing an appropriate error message to cerr.
{
    struct tree_node *tnp = (struct tree_node *)tree;
 
    if ((tnp->tn_id != tree_node_id) && (tnp->tn_id != tree_empty_id)) {
        std::cerr << "Error: user pass invalid tree\n";
        //assert(0);
    }
    return tnp;
}
static void
tree_checkNonEmpty(tree_t tree)
{
  if (tree_isEmpty(tree))  {
      std::cerr << "Error: user pass empty tree\n";
     // assert(0);
    }
}
bool
tree_isEmpty(tree_t tree)
{
    struct tree_node *tnp = tree_checkValid(tree);
    return (tnp->tn_id == tree_empty_id);
}
 
tree_t
tree_make()
{
    struct tree_node *tnp = 0;
 
    try 
    {
      tnp = new struct tree_node;
    } 
        catch (std::bad_alloc a) 
    {
      //not_allocated();
    }
    tnp->tn_id = tree_empty_id;
    tnp->tn_left = NULL;
    tnp->tn_right = NULL;
    return tnp;
}
tree_t
tree_make(int elt, tree_t left, tree_t right)
{
    struct tree_node *tnp = 0;
    try 
    {
        tnp = new struct tree_node;
    } 
        catch (std::bad_alloc a) 
    {
        //not_allocated();
    }
 
    if (!tree_isEmpty(left)) 
    {
      tree_checkValid(left);
    }
    if (!tree_isEmpty(right)) 
    {
      tree_checkValid(right);
    }
    tnp->tn_id = tree_node_id;
    tnp->tn_elt = elt;
    tnp->tn_left = (struct tree_node *)left;
    tnp->tn_right = (struct tree_node *)right;
    return tnp;
}
int
tree_elt(tree_t tree)
{
    tree_checkNonEmpty(tree);
    struct tree_node *tnp = tree_checkValid(tree);
    return tnp->tn_elt;
}
tree_t
tree_left(tree_t tree)
{
    tree_checkNonEmpty(tree);
    struct tree_node *tnp = tree_checkValid(tree);
    return tnp->tn_left;
}
tree_t
tree_right(tree_t tree)
{
    tree_checkNonEmpty(tree);
    struct tree_node *tnp = tree_checkValid(tree);
    return tnp->tn_right;
}
static void
print_spaces(int spaces)
    // MODIFIES: cout
    // EFFECTS: prints n spaces
{
  while (spaces--) 
 {
      std::cout << "  ";
    }
}
static void
tree_print_internal(tree_t tree, int spaces)
    // MODIFIES: cout
    // EFFECTS: prints tree contents recursively, with newlines 
    //          for each node, with each level indented
{
  print_spaces(spaces);
    if (tree_isEmpty(tree)) 
    {
       std::cout << "( )\n";
    } else {
      std::cout << "(" << tree_elt(tree) << "\n";
        tree_print_internal(tree_left(tree), spaces+1);
        tree_print_internal(tree_right(tree), spaces+1);
        print_spaces(spaces);
        std::cout << " )\n";
    }
}
void
tree_print(tree_t tree)
{
  tree_print_internal(tree, 0);
}

In: Computer Science

Study the research papers and write a report on the following Agile Software Development Methods (ASDMs)...

  1. Study the research papers and write a report on the following Agile Software Development Methods (ASDMs)
  1. Adaptive Software Development (ASD)
  2. Dynamic System Development Method (DSDM)
  3. Crystal
  4. Feature Driven Development (FDD)
  1. Conduct a comparative analysis between Traditional Software Development Methods (TSDMs) and Agile Software Development Methods (ASDMs)
  2. Attach the Plagiarism report for your document

In: Computer Science

Below is some code for a rectangle class that needs to be completed. Add member function...

Below is some code for a rectangle class that needs to be completed. Add member function declarations to the class declaration and member function definitions below the declaration. For the accessor functions, you can add the definitions directly into the class declaration. The goal is to code the class so that it works wthout changing the main program

#include <iostream>
using namespace std;

// rectangle has a vertical height and horizontal width
// The class below is a rectangle. It has two private
// data members: height and width.
// TODO: Complete the class declaration and definition.
class rectangle {
public:
// TODO: declare a default constructor
// Make the height and width = 1.
  
// TODO: declare member function void add
// @param int height, int width

// TODO: delcare member function void set
// @param int height, int width
  
// TODO: declare member function void draw
  
// TODO: define accessor for width
  
// TODO: define accessor for height
  
private:
int width;
int height;
};

// TODO: define the default constructor that
// sets height and width to 1.
rectangle::rectangle()
{

}

// TODO: Implement add to increment the length
void rectangle::add(int h, int w)
{

}

// TODO: Implement set to overwrite the data members
void rectangle::set(int h, int w)
{

}

// TODO: Implement draw to draw a rectangle using '*' characters
void rectangle::draw()
{
  
  
}

// TODO: Don't forget to define getWidth and getHeight


int main()
{
// Declare 2 rectangles
rectangle r1, r2;
  
// Print the unit rectangle
cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;
  
// Set, print dimensions and draw
r1.set(4, 3);
cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;
r1.draw();
  
// Assign, increment, print dimensions and draw
r2 = r1;
r2.add(3, 4);
cout << "r2 is " << r2.getHeight() << " x " << r2.getWidth() << endl;
r2.draw();
  
return 0;
}

In: Computer Science

Find the closed form for the following series: 1 + x2 + x3 + … +...

Find the closed form for the following series: 1 + x2 + x3 + … + xn where x is constant and x > 1

In: Computer Science

in java Design and implement a class named Person and its two subclasses named Student and...

in java

Design and implement a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name,address, phone number, and email address. A student has a class status (year 1,year 2,year 3,or year 4). An employee has an office, salary, and date hired. Use the Date class from JavaAPI 8 to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.Design and implement all 5classes. Write a test program that creates a Person,Student,Employee,Faculty, and Staff, and iinvokes their toString()methods

In: Computer Science

For C++ Use arrays and or vectors, no classes. Visualize and consider 100 lockers all lined...

For C++ Use arrays and or vectors, no classes.

Visualize and consider 100 lockers all lined up horizontally in a row
Each locker is numbered from 1 to 100 in sequential order

Every locker can be fully closed (open state = 0.00)
Every locker can be fully opened (open = 1.00)
Every locker can be partially open with any possible value between 0.00 and 1.00 inclusive on both ends
A locker cannot ever be more closed than fully closed (open cannot be less than 0.00)
A locker cannot ever be more open than fully opened (open cannot be greater than 1.00)

All 100 lockers start in the fully closed state
100 students will be walking by the lockers and opening/closing them in the following manner:

The 1st student will OPEN EVERY LOCKER       1/2 of the way (ADD 0.50 TO LOCKERS 1,2,3,4...)

The 2nd student will CLOSE EVERY SECOND LOCKER 1/3 of the way (SUBTRACT 0.333333333333 FROM LOCKERS 2,4,6,8...)

The 3rd student will OPEN EVERY THIRD LOCKER   1/4 of the way (ADD 0.25 TO LOCKERS 3,6,9,12...)

The 4th student will CLOSE EVERY FOURTH LOCKER 1/5 of the way (SUBTRACT 0.20 FROM LOCKERS 4,8,12,16...)

The 5th student will OPEN EVERY FIFTH LOCKER   1/6 of the way (ADD 0.166666666666 TO LOCKERS 5,10,15,20...)

The 6th student will CLOSE EVERY SIXTH LOCKER 1/7 of the way (SUBTRACT 0.142857142857 FROM LOCKERS 6,12,18,24...)

The 99th student will OPEN EVERY 99TH LOCKER   1/100 of the way (ADD 0.01 TO LOCKER 99)

The 100th student will CLOSE EVERY 100TH LOCKER 1/101 of the way (SUBTRACT 0.009900990099 FROM LOCKER 100)

NOTE: Remember that the locker open state must always stay within 0.00 <= value <= 1.00

1) Develop C++ code that will generate the open state values for all 100 lockers

2) Also develop C++ code that will output answers to the following questions:

Which lockers are left fully closed (open state == 0.00)?

Which lockers are left fully open (open state == 1.00)?

Which locker is the one opened the least and what is its value (open state closest to 0.00)?

Which locker is the one closed the least and what is its value (open state closest to 1.00)?

In: Computer Science

Construct two small C programs, compile and set up two executable files for the two commands...

Construct two small C programs, compile and set up two executable files for the two commands world and mars. Both commands simply print out messages on the screen:

world n - print the message hello world on the screen n times

mars n - print the message HELLO MARS on the screen n times

Thanks a lot for your help!!!

In: Computer Science

When creating the Academic Database, there were several instances of data validation. Data types were assigned...

When creating the Academic Database, there were several instances of data validation. Data types were assigned to each field in the table to stop undesirable values from being placed into certain fields. A presence check was used on fields that were listed as NOT NULL, requiring some data to be input. Uniqueness validation was automatically assigned for fields that were primary keys. Describe at least one field in the Academic Database a table where range validation could have been used and describe at least one field in the Academic Database where choice validation could have been used. Your answer should be addressed in 100 to 150 words.

In: Computer Science

OpenGL problem Draw the entire scene composed with more than 5 objects. Scene should Include rigid...

OpenGL problem

Draw the entire scene composed with more than 5 objects. Scene should Include rigid transformations such as scale, rotate, translate, etc.

And please write down the code of the application program.cpp file (files containing main, render, etc). Also, show the picture of captured result screen.

you should give 1. code of the application program.cpp, 2. picture of captured result screen(entire scene). Please don't give incomplete answer.

In: Computer Science

suppose i have a list in python that is [hello,yo,great,this,cool,fam] how do I get all the...

suppose i have a list in python that is [hello,yo,great,this,cool,fam]

how do I get all the possible 2 combination that I can have from this list in tuples for example output

[ {hello,hello},{hello,yo},{hello,great},....... {yo,hello},{yo,yo} and so on and son}

no packages allowed

In: Computer Science

5.25. The following pseudocode (next page) is a correct implementation of the producer/consumer problem with a...

5.25. The following pseudocode (next page) is a correct implementation of the producer/consumer problem with a bounded buffer:

Labels p1, p2, p3 and c1, c2, c3 refer to the lines of code shown above (p2 and c2 each cover three lines of code). Semaphores empty and full are linear semaphores that can take unbounded negative and positive values. There are multiple producer processes, referred to as Pa, Pb, Pc, etc., and multiple consumer processes, referred to as Ca, Cb, Cc, etc. Each semaphore maintains a FIFO (first-in-first-out) queue of blocked processes. In the scheduling chart below, each line represents the state of the buffer and semaphores after the scheduled execution has occurred. To simplify, we assume that scheduling is such that processes are never interrupted while executing a given portion of code p1, or p2, . . . , or c3. Your task is to complete the following chart.

item[3] buffer; // initially empty

semaphore empty; // initialized to +3

semaphore full; // initialized to 0

binary_semaphore mutex; // initialized to 1

void producer()

void consumer()

{

{

   ...

   ...

   while (true) {

   while (true) {

       item = produce();

c1:     wait(full);

p1:   wait(empty);

 /    wait(mutex);

 /         wait(mutex);

c2:     item = take();

p2:   append(item);

 \    signal(mutex);

 \      signal(mutex);

c3:     signal(empty);

p3:   signal(full);

         consume(item);

   }

   }

}

}

Scheduled Step of Execution

full’s State and Queue

Buffer

empty’s State and Queue

Initialization

full=0full=0

OOO

empty=+3empty= +3

Ca executes c1

full=−1full= −1 (Ca)

OOO

empty=+3empty= +3

Cb executes c1

full=−2full= −2 (Ca, Cb)

OOO

empty=+3empty= +3

Pa executes p1

full=−2full= −2 (Ca, Cb)

OOO

empty=+2empty= +2

Pa executes p2

full=−2full= −2 (Ca, Cb)

X   OO

empty=+2empty= +2

Pa executes p3

full=−1full= −1 (Cb) Ca

X   OO

empty=+2empty= +2

Ca executes c2

full=−1full= −1 (Cb)

OOO

empty=+2empty= +2

Ca executes c3

full=−1full= −1 (Cb)

OOO

empty=+3empty= +3

Pb executes p1

full= full=

empty= empty=

Pa executes p1

full= full=

empty= empty=

Pa executes __

full= full=

empty= empty=

Pb executes __

full= full=

empty= empty=

Pb executes __

full= full=

empty= empty=

Pc executes p1

full= full=

empty= empty=

Cb executes __

full= full=

empty= empty=

Pc executes __

full= full=

empty= empty=

Cb executes __

full= full=

empty= empty=

Pa executes __

full= full=

empty= empty=

Pb executes p1-p3

full= full=

empty= empty=

Pc executes __

full= full=

empty= empty=

Pa executes p1

full= full=

empty= empty=

Pd executes p1

full= full=

empty= empty=

Ca executes c1-c3

full= full=

empty= empty=

Pa executes __

full= full=

empty= empty=

Cc executes c1-c2

full= full=

empty= empty=

Pa executes __

full= full=

empty= empty=

Cc executes c3

full= full=

empty= empty=

Pd executes p2-p3

full= full=

empty=

In: Computer Science

You’ve implemented the Academic Database in a local school in your community. The school’s administrator decides,...

  1. You’ve implemented the Academic Database in a local school in your community. The school’s administrator decides, there’s no need for database backup and recovery plan because all their computers are new. Explain in 100 to 150 words why there needs to be a disaster recovery plan.

In: Computer Science

Scenario:             Startup company established on 01/01/20XX has 12 people personnel of which one executive director,...

Scenario:

            Startup company established on 01/01/20XX has 12 people personnel of which one executive director, one CIO one manager of software one manager of hardware one CFO and 5 engineers and one secretary, which plays role of public relations as well apart from day to day data management duties.

            The company develops hardware and software for resolvers which sells on larger companies. Some of the contracts include the company to be supplier of a larger company which has government contracts.

            The company exploits one central server with 100 nodes, shared storage, shared data space similar to DropBox, shared scanner and 10 printers.

            All workstations were placed in cubicles in main room and the secretary desk and workstation along with 2 printers was set up at main entrance hallway.

Q1. On March 10/20XX the new server was delivered and mangers along with CIO and executive director made a meeting to establish a policy of use of the resource. It was decided that:

  • All engineers’ personnel and CIO will have access to all files 365/24 remotely and from their office workstations.
  • The CFO will have access only to data dealing with matherials for current month.
  • The Executive director will have access only to CIO reports and CFO reports but not data on projects.
  • Secretary will have all access to all documents and data all the time.

Do you think this set up have security risks? Describe these risks if any and propose a better solution and describe why your solution is better.   

In: Computer Science

C++ give some examples of where you could use the stream manipulators to format output.

C++ give some examples of where you could use the stream manipulators to format output.

In: Computer Science

Demonstrate, with a program, if this is true or false :Scope is the portion of a...

Demonstrate, with a program, if this is true or false

:Scope is the portion of a program that can refer to an entity by its simple name

In: Computer Science