Question

In: Computer Science

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

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];
};

Solutions

Expert Solution

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>

#include <ctime>

using namespace std;

int main()
{

clock_t start_s=clock();

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();

clock_t stop_s=clock();
cout << "\nExecution time: "<< (double)(stop_s - start_s)/CLOCKS_PER_SEC << endl;

system("pause");
return 0;
}

 

Related Solutions

Whenever an exception arises, it terminates the program execution, which means it stops the execution of...
Whenever an exception arises, it terminates the program execution, which means it stops the execution of the current java program. a) Identify and explain how the remedy for the exception is considered. b) Implement the above-identified remedy in the java program to overcome the problem raised in the exceptional case when we try to open and close the files.
build a program which performs matrix multiplication on square matrices. use UNIX "time" to capture the...
build a program which performs matrix multiplication on square matrices. use UNIX "time" to capture the time it takes to run the program with different data sizes. Languages: Python Task: Create matrix multiplication Input: Size of square matrix.   Size should be    250, 500, 1000, 1500, 2000 Internals: Explicitly or implicitly allocate sufficient memory to hold three NxN floating point Matrices, using a random number generator -- populate two of the Matrices, Multiply the two matrices, putting the result into the...
Program #1: You will be writing code for several different examples of conditional execution. Each example...
Program #1: You will be writing code for several different examples of conditional execution. Each example should be written as a unique method. Each method should include a method header. So the basic outline of your code is: public class Branching { /** * This is an example method header. Notice how it's multi-line and written * using college-level English and not fragments - this is for the Human to * read and not the compiler to parse, so be...
* Make sure you turn in your code (take a screen shot of your code in...
* Make sure you turn in your code (take a screen shot of your code in R)and answers. Conduct the hypothesis and solve questions by using R. 2) A random sample of 12 graduates of a secretarial school averaged 73.2 words per minute with a standard deviation of 7.9 words per minute on a typing test. What can we conclude, at the .05 level, regarding the claim that secretaries at this school average less than 75 words per minute on...
Make a detailed trace of the execution of the following program fragment, giving the contents of...
Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively. SS SP TOS AX BX CX DX Initial contents 0990 0100 / 789A 0020 2000 1234 after PUSH AX after PUSH BX after PUSH CX...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
Trace the execution of the following program assuming the input stream contains the numbers 10, 3,...
Trace the execution of the following program assuming the input stream contains the numbers 10, 3, and 14.3. Use a table that shows the value of each variable at each step. Also show the output (exactly as it would be printed) // FILE: Trace.java // PURPOSE: An exercise in tracing a program and understanding // assignment statements and expressions. import java.util.Scanner; public class Trace { public static void main (String[] args) { int one, two, three; double what; Scanner scan...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT