Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Test the execution time of the program in Code 3. Make a screen capture which

ID: 3796231 • Letter: 1

Question

1.       Test the execution time of the program in Code 3. Make a screen capture which shows the execution time that has the unit of machine time unit.

Code3

SOURCE.CPP

# include<fstream>
# include "List.h"
# include <iostream>
using namespace std;

int main()
{
List temps;
int oneTemp;
ifstream inData;
ofstream outData;

inData.open("temp.dat");
if (!inData)
{
  outData<<"Can't open file temp.dat" << endl;
  return 1;
}

inData >> oneTemp;
while (inData && !temps.IsFull())
{
  if (!temps.IsPresent(oneTemp))
   temps.Insert(oneTemp);
  inData >> oneTemp;
}

outData << "No. of uniqiue readings:" << temps.Length() << endl;
temps.Reset();
while (temps.HasNext())
{
  oneTemp = temps.GetNextItem();
  outData << oneTemp << endl;
}
temps.Delete(23);

outData << "Readings without value of 23." << endl;
temps.Reset();
while (temps.HasNext())
{
  oneTemp = temps.GetNextItem();
  outData << oneTemp << endl;
}

temps.SelSort();
outData << "Readings after the sort algorithm." << endl;
temps.Reset();
while (temps.HasNext())
{
  oneTemp = temps.GetNextItem();
  outData << oneTemp << endl;
}
inData.close();
outData.close();

system("pause");
return 0;
}

LIST.CPP

// Implementation file array-based list
// (“list.cpp”)

#include "List.h"
#include <iostream>

using namespace std;

List::List()
// Constructor
// Post: length == 0
{
length = 0;
}

int List::Length() const
// Post: Return value is length
{
return length;
}
bool List::IsFull() const
// Post: Return value is true
//       if length is equal
// to MAX_LENGTH and false otherwise
{
return (length == MAX_LENGTH);
}
bool List::IsEmpty() const
// Post: Return value is true if length is equal
// to zero and false otherwise
{
return (length == 0);
}

void List::Insert(/* in */ ItemType item)
// Pre: length < MAX_LENGTH && item is assigned
// Post: data[length@entry] == item &&
//       length == length@entry + 1
{
data[length] = item;
length++;
}

void List::Delete( /* in */ ItemType item)
// Pre: length > 0 && item is assigned
// Post: IF item is in data array at entry
//  First occurrence of item is no longer
//   in array
//     && length == length@entry - 1
//  ELSE
//       length and data array are unchanged
{
int index = 0;

while (index < length &&
  item != data[index])
  index++;
// IF item found, move last element into
// item’s place
if (index < length)
{
  data[index] = data[length - 1];
  length--;
}
}

ItemType List::GetNextItem()
// Pre: No transformer has been executed since last call
// Post:Return value is currentPos@entry
//   Current position has been updated
//   If last item returned, next call returns first item
{
ItemType item;
item = data[currentPos];
if (currentPos == length )
  currentPos = 0;
else
  currentPos++;
return item;
}

bool List::IsPresent( /* in */ ItemType item) const
// Searches the list for item, reporting
//   whether found
// Post: Function value is true, if item is in
//   data[0 . . length-1] and is false otherwise
{
int index = 0;
while (index < length && item != data[index])
  index++;
return (index < length);
}

void List::SelSort()
// Sorts list into ascending order
{
ItemType temp;
int passCount;
int sIndx;
int minIndx; // Index of minimum so far   
  for (passCount = 0; passCount < length - 1; passCount++)
  {
   minIndx = passCount;
   // Find index of smallest value left
   for (sIndx = passCount + 1; sIndx < length; sIndx++)
    if (data[sIndx] < data[minIndx])
     minIndx = sIndx;
   temp = data[minIndx];  // Swap
   data[minIndx] = data[passCount];
   data[passCount] = temp;
  }
}

void List::Reset()
{
currentPos = 0;
}

bool List::HasNext() const
{
return(currentPos != length);
}

LIST.H

#pragma once
#include<iostream>
using namespace std;

const int MAX_LENGTH = 110000;
typedef int   ItemType;

class List           // Declares a class data type
{
public:            // Public member functions

List();           // constructor
bool IsEmpty() const;
bool IsFull() const;
int Length() const; // Returns length of list
void Insert(ItemType item);
void Delete(ItemType item);
bool IsPresent(ItemType item) const;
void Reset();
ItemType GetNextItem();
void SelSort();
bool HasNext() const;

private:       // Private data members

int length; // Number of values currently stored
int currentPos; // Used in iteration
ItemType data[MAX_LENGTH];
};

Explanation / Answer

NOTE: Please provide temp.dat

If you want the screenshort please provide temp.dat

But if u can run the program by yourself then please make these changes in SOURCE.CPP

Changes have been marked in bold

# include<fstream>
# include "List.h"
# include <iostream>

using namespace std;

int main()
{

List temps;
int oneTemp;
ifstream inData;
ofstream outData;

inData.open("temp.dat");
if (!inData)
{
  outData<<"Can't open file temp.dat" << endl;
  return 1;
}

inData >> oneTemp;
while (inData && !temps.IsFull())
{
  if (!temps.IsPresent(oneTemp))
   temps.Insert(oneTemp);
  inData >> oneTemp;
}

outData << "No. of uniqiue readings:" << temps.Length() << endl;
temps.Reset();
while (temps.HasNext())
{
  oneTemp = temps.GetNextItem();
  outData << oneTemp << endl;
}
temps.Delete(23);

outData << "Readings without value of 23." << endl;
temps.Reset();
while (temps.HasNext())
{
  oneTemp = temps.GetNextItem();
  outData << oneTemp << endl;
}

temps.SelSort();
outData << "Readings after the sort algorithm." << endl;
temps.Reset();
while (temps.HasNext())
{
  oneTemp = temps.GetNextItem();
  outData << oneTemp << endl;
}
inData.close();
outData.close();

system("pause");
return 0;
}