C++ CST 280 Week 2 Practice A and B - 74121

Solution Posted by
jordanblink

jordanblink

Rating : (19)A+
Solution Detail
Price: $20.00
Request Description

CST 280 In-Class Practice – Week 2 A

Access the file unorderPrac.cpp from the course web materials (code pq6v). 

Create a new Visual C++ project. A file is required – you can either create your own of 

use an example from the course materials.

Then, complete the two missing functions that will insert a new element at the front of 

an unordered list. 

UnOrdInsertFrontRand : Insert an element at front of the list without any 

regard to the impact to the order of other elements in the list. List items can end 

up anywhere as long as they remain in the list.

UnOrdInsertFrontFixed Insert an element at front of the list while 

maintaining the given sequence of the other elements in the list.

/************************************************************/

/* This function receives an integer, an array containing */

/* an unordered list, and the size of the list. It inserts */

/* a new integer item at the beginning of the list. */

/* */

/************************************************************/

void UnOrdInsertFrontRand(int list[], int& numElems, int newint)

 

 

 

}

/************************************************************/

/* This function receives an integer, an array containing */

/* an unordered list, and the size of the list. It inserts */

/* a new integer item at the beginning of the list. */

/* */

/* POSTCONDITION: Order of original list is undisturbed. */

/************************************************************/

void UnOrdInsertFrontFixed(int list[], int& numElems, int newint)

 

 

 

}

Deliverables: Demonstrate program source code and output to your instructor

 

-----------------------------------------------------------------------------------------------------------------------

 

CST 280 In-Class Practice – Week 2

Access the following files from the course web materials via code ty4a:

data file listWork.cpp

data file list1.txt

data file list2.txt

Create a new Visual C++ project. Additional required algorithms can be accessed from 

the course web page, development on the board, and below. All algorithms exist –

none have to be developed from scratch.

In its current form, this program will read two lists into arrays and display them. Using 

the examples discussed in class, perform the following actions on the two lists.

1) Display both lists (DONE)

2) Reverse the order of List 1

3) Remove duplicates from List 2 (key in algorithm below)

4) Display both lists

5) For List 1: insert values 14 and 24, and delete the value 11

6) Merge List 1 and List 2 together into List 3

7) Display combined list: List 3

A new function is provided below that will remove any duplicates within an ordered list 

of values. This code below will need to be keyed into your program.

/************************************************************/

/* This function receives an ordered list of integers and */

/* removes duplicate values (in adjacent storage elements) */

/************************************************************/

void RemoveDuplicates(int theList[], int& listSize)

{

 int i,j;

 i = 0;

 while (i < listSize-1) // For all list elements (up to last)

 {

 if (theList[i] == theList[i+1]) // if next list item is duplicate

 {

 for (j=i; j<listSize-1; j++) // then move elements back one space

 theList[j] = theList[j+1]; // to overlay the duplicate

 listSize--; 

 }

 else

 i++; // otherwise, go to next element 

 } 

}

Run the program and test until you are satisfied the output is correct. The final list 

should be:

2 3 4 5 6 7 8 9 10 11 13 14 15 18 20 21 22 23 24 25 28 29 31 33 34 36 45

Deliverables: Demonstrate program source code and output to your instructor

Solution Description

CST 280 In-Class Practice – Week 2 A

Access the file unorderPrac.cpp from the course web materials (code pq6v). 

Create a new Visual C++ project. A file is required – you can either create your own of 

use an example from the course materials.

Then, complete the two missing functions that will insert a new element at the front of 

an unordered list. 

UnOrdInsertFrontRand : Insert an element at front of the list without any 

regard to the impact to the order of other elements in the list. List items can end 

up anywhere as long as they remain in the list.

UnOrdInsertFrontFixed Insert an element at front of the list while 

maintaining the given sequence of the other elements in the list.

/************************************************************/

Attachments
CPPCST280W2.zip
CPPCST280W2.zip