Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It won't let me post the code for you to edit. Only images. Any suggestions? Please hurry! Please use the prompt below and files to

It won't let me post the code for you to edit. Only images. Any suggestions?

Please hurry! Please use the prompt below and files to implement the functions as requested. Thank you image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Sequence4.h

image text in transcribed

image text in transcribed

image text in transcribed

Sequence4.template

image text in transcribed

The goal of this assignment is to reinforce using stacks in C++ programs. Specifically, the assignment is to do The following problem. Use the STL stack class, sequence4.h, and sequence_exam4.cpp for this assignment. Here's a new idea for implementing the sequence class. Instead of the items being stored on a linked list, they will be stored using two stacks as private member variables with the following: 1. Imagine the two stacks glued together with their tops right next to each other. 2. The bottom of the first stack is the beginning of the sequence. 3. The elements of the sequence continue up to the top of the first stack. 4. The next element of the sequence is then the top of the second stack. 5. And the elements of the sequence then continue down to the bottom of the second sequence (which is the end of the sequence). 6. If there is a current element, then that element is at the top of the second stack. Don't change any of the prototypes for any of the public member functions. All of the public member functions should take constant time with one exception. Which one takes linear time? Note: If you use a correctly written stack class for your two private member variables, then you do not need to write your own assignment operator, copy constructor, or destructor. The reason for this is that C++ provides automatic versions of all three of these items, and the automatic versions call the respective functions for each of the member variables of the new class 1 / FILE: sequence exam4.cxx 2 Written by: Michael Main (main@colorado.edu)Oct 31, 1997 3// Non-interactive test program for the sequence class using a linked 5: // DESCRPTION: 6 / Bach function of this program tests part of the sequence class, returning 7 // some number of points to indicate how much of the test was passed. 8// A description and result of each test is printed to cout. 9 // Maximum number of points awarded by this program is determined by the 10// constants POINTS [1], POINTS (2]... 12 finclude 13 finclude 14 finclude "sequence4.h" // Provides the template sequence class 15 using namespace std: 16 using namespace stack sequence 4; 17 / Provides cout. // Provides size t. 18 conpescriptlons and points for oach of the testa 19 const size t MANY TESTS 6 20 const int POINTS [MANY TESTS+1] 21 18, ITotal points for all tests 23 24 25 26 4, / Test 1 points 4, I/ Test 2 points 4, 11 Test 3 points 2, I/ Test 4 points 2, 11 Test 5 points 72 // Test 6 points 28 1i 29 const char DESCRIPTION [MANY_TESTS+1] 1256 30 31 32 "tests for sequence Class with a linked sequence", "Testing insert, attach, and the constant member functions", "Testing situations where the cursor goes off the sequence", "Testing remove current", "Testing the copy constructor", "Testing the assignment operator", 35 35 36 "Testing the assignment operator" "Testing insert/attach for somewhat larger sequences" 39 // bool test basic(const sequence& test, size t s, bool has cursor) 40/ Postcondition: A return value of true indicates: 41 7/ a. test.size() is s, and b. test.is item () is has cursor. 43 // Otherwise the return value is false 44 In either case, a description of the test result is printed to cout. 46 bool test basic (const sequence& test, sizet s, bool has cursor) 47 ( 48 bool answer? 49 50 51 52 53 cout & test, size-t s, sizet i, double items[]) 68 / The function determines if the test sequence has the correct items 69/ Precondition: The size of the items array is at least s 70 Postcondition: A return value of true indicates that test.current 0 71/ is equal to itemsli], and after test.advance () the result of 72test.current() is items[i+1, and so on through items [s-1]. At this point, one more advance takes the cursor off the sequence. 74/ If any of this fails, the return value is false. 75 NOTE: The test sequence has been changed by advancing its cursor. 77 booi test-items (sequence& test, size-t s, size-t , double items[]) 78 I 79 80 81 cout & test, size t s, size t cursor spot, double items[]) 115 // This function determines if the sequence (test) is "correct" according to 116/ these requirements: 117 a. it has exactly s items. 118 / b. the items (starting at the front) are equal to items [0]items [s-1] 120c. if cursor spot = s, then test must not have a cursor. 123// NOTE: The function also moves the cursor off the sequence 124/ 125 bool correct 127 ( 128 bool has-cursor = (cursor-spot empty; sequence test; double items1 [4]5, 10, 20, 30I These 4 items are put in a sequenc / A sequence to add items to 166 double items2 [4]10, 15, 20, 30 / These are put in another sequence 167 168 169 170 if (correct (empty, 0, 0, items1)) return 0 // Test that the empty sequence is really empty cout test: size t i cout testi 304 305 306 307 double items1 [1] 30 308 double items2 [2] { 10, 30 }; 309 double items3 [3] 10, 20, 30 310 311 312 313 const size_t TESTSIZE 30: // Within this function, I create several different sequences using the // items in these arrays: size t i // for-loop control variable // Build a sequence with three items 10, 20, 30, and remove the middle, // Build a sequence with three items 10, 20, 30, and remove the middle, // and last and then first. 313 314 315 cout original: / A sequence that we'11 copy 395 396 397 398 /1 Set up the items array to conatin 1.. .2 TESTSIZE. 399 for (i l; i copyl (original) 405 original.attach (1) / Changes the original sequence, but not the copy. 406 if (correct (copyl, 0, 0, items)) return 0 407 408 409 410 412 411 414 413 original.remove_current) // Delete tail from original, but not the copy 415 original.advance () 416 original.remove_ current // Delete 2 from original, but not the copy. 417 I Test copying of a sequence with current item at the tall1 cout copy2 (original) original.start( if (correct if (correct 417 418 419 420 421 (copy2, 2 TESTSIZE, 2*TESTSIZE-1, items) return 0 422 / Test copying of a sequence with cursor near the middle. 423 cout copy3 (original): 429 original.start( 30 original.advance( original.advance ( / Cursor is now at location [TESTSIZE) (counting [0] as the first spot) 431 original.remove_current):/ Dolete 2 from original, but not the copy. 432 433 434 435 436 437 if (correct (copy3, 2*TESTSIZE-1, TESTSIZE, items) return 0 // Test copying of a sequence with cursor at the front. 438 cout"Copy constructor test: for a sequence with cursor at Eront." copy4 (original) 443 original.start 444 original.advance( 445 original.remove_current / Delete 2 from original, but not the copy. /Cursor is now at the front. if (correct (copy4, 2 TESTSIZE-1, 0, items) 447 448 449 450 451 return 0 // Test copying of a sequence with no current item. 451 452 453 / Test copying of a sequence with no current item cout copy5(original); 458 original.start 459 original.advance () 460 original.remove_ current : // Delete 2 from original, but not the copy. 461 if (correct 462 463 465 464 466 467 cout originali 1 A sequence that we'll copy 479 double items [2 TESTSIZE] 480 481 482 1/ Set up the items array to conatin 1.. .2 TESTSIZE. 483 for (i = 1; copyl; copyl original: original.attach(1): 1/ Changes the original sequence, but not the copy if (correct (copyl, 0, 0, items)) return 0 // Test copying of a sequence with current item at the tail cout copy2: copy2 original: // Delete tail from original, but not t 500 original.start( original.advance( 5 501 02 original.remove current (): Delete 2 from original, but not the copy. 503 504 505 506 507 if (correct (copy2, 2 TESTSIZE, 2*TESTSIZE-1, items) return 0 508 / Test copying of a sequence with cursor near the middle cout copy3: copy3 = original; 17 original.advance ( 518 original.remove_ current): / Delete 2 from original, but not the copy. 519 if (correct 520 (copy3, 2*TESTSIZE-1, TESTSIZE, items) 521 522 523 524 525 526 527 528 529 530 531 original.start ( 532 original.advance(): 533 original.remove_current ): /Delete 2 from original, but not the copy return 0; // Test copying of a sequence with cursor at the front. cout xx "Assignment operator test: with cursor at front." copy4 copy4 original: 34 if (correct 535 536 537 538 539 540 541 542 while (original.is_item)) 543 544 545 (copy4, 2*TESTS IZE-1, o, items) return 0; // Test copying of a sequence with no current item. cout testa, testi; size t ii // Set up the items array to conatin 1.. .2 TESTSIZE. 2*TESTS IZE; i++) (i items [i-1]ii for l; i = 1; i--) testi.insert (i) i (testi, 2 TESTSIZE, 0, items) return 0 if (correct 599 600 601 602 // All tests passed 603 cout // Provides size.t 54 #include 55 namespace stack_sequence 4 56 t 57 template 58 59 60 public: 61 62 63 64 65 class sequence // TYPEDEFS and MEMBER CONSTANTS typedef std::size t size type: / CONSTRUCTOR sequence ) // MODIFCATION MEMBER FUNCTIONS void start( void advance void insert (const T& entry) void attach (const T& entry) ; 67 68 69 69 70 71 72 73 74 75 private: 76 void attach (const T& entry) void remove current () // CONSTANT MEMBER FUNCTIONS size type size) const (return first.size0+second.size):) bool is item const: T current( const std: :stack first; std::stack 3 #include // Provides size_t 5 namespace stack_sequence4 6 //Implement all the functions here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago