SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 23 Oct 2017 My Price 10.00

This week you convert the operator<< function to use a recursive

This week you convert the operator<< function to use a recursive solution and add a recursive exists function that determines whether a particular integer value exists within the IntList.

IntList.h

The following is the IntList.h file you must use. DO NOT add anything to this file.

#ifndef __INTLIST_H__
#define __INTLIST_H__

#include <ostream>

using namespace std;

struct IntNode {
    int data;
    IntNode *next;
    IntNode(int data) : data(data), next(0) {}
};


class IntList {

 private:
   IntNode *head;

 public:

   /* Initializes an empty list.
   */
   IntList();

   /* Inserts a data value to the front of the list.
   */
   void push_front(int);

   /* Outputs to a single line all of the int values stored in the list, each separated by a space. 
      This function does NOT output a newline or space at the end.
   */
   friend ostream & operator<<(ostream &, const IntList &);

   /* Returns true if the integer passed in is contained within the IntList, 
      otherwise returns false.
   */
   bool exists(int) const;

 private:


   /* Helper function that returns true if the integer passed in is contained within
      the IntNodes starting from the IntNode whose address is passed in,
      otherwise returns false.
   */
   bool exists(IntNode *, int) const;
};

/* Helper function that passes in the address of a IntNode within an IntList and outputs
   all of integers within the IntList starting from this IntNode.
*/
ostream & operator<<(ostream &, IntNode *);


#endif

main function

Use the following main function to pass the first 2 tests in zyBooks.

int main() {
   IntList test1;
   IntList test2;
   int testNum;

   cout << "Enter test number: ";
   cin >> testNum;
   cout << endl;

   // Test operator<< function
   if (testNum == 1) {
      // output empty list
      cout << "Empty : " << test1 << "T" << endl;

      // output list of size 1
      test1.push_front(3);
      cout << "Size 1: " << test1 << "T" << endl;

      // output list of size 2
      test1.push_front(0);
      cout << "Size 2: " << test1 << "T" << endl;

      // output list of size 5
      test1.push_front(-3);
      test1.push_front(8);
      test1.push_front(0);
      cout << "Size 5: " << test1 << "T" << endl;
   }

   // Test exists function
   if (testNum == 2) {

      // test on empty list
      cout << "Empty: " << test2.exists(0) << endl;

      test2.push_front(-4);

      // test on list of size 1, doesn't exist
      cout << "Size 1 (doesn't exist): " << test2.exists(-1) << endl;

      // test on list of size 1, does exist
      cout << "Size 1 (does exist): " << test2.exists(-4) << endl;

      test2.push_front(-5);
      test2.push_front(4);
      test2.push_front(0);
      test2.push_front(6); // {6 0 4 -5 -4}

      // test on list of size 5, doesnt' exist
      cout << "Size 5 (doesn't exist): " << test2.exists(1) << endl;

      // test on list of size 5, exists in head
      cout << "Size 5 (exists in head): " << test2.exists(6) << endl;

      // test on list of size 5, exists in tail
      cout << "Size 5 (exists in tail): " << test2.exists(-4) << endl;

      // test on list of size 5, exists somewhere in middle
      cout << "Size 5 (exists in middle): " << test2.exists(0) << endl;
   }

   return 0;
}

Answers

(5)
Status NEW Posted 23 Oct 2017 02:10 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)