
Hall H.
asked 04/06/21Linux help Assignment Urgent help!
For this assignment you will write a program that allows a user to enter
timing data (minutes and seconds) and then print out some information about
the entered data.
- the program reads input according to the instructions.txt
- the program calculates the average correctly
- the program calculates the fastest time correctly
- the program calculates the slowest time correctly
- the program outputs all times values in the correct format
- uses a do-while loop to read in values
- uses setw and setfill to output the time values
- no global variables
- all variables are given meaningful names
1) prompt the user to enter two integers with this text: "Enter min sec: "
2) allow the user to enter them
3) print out the two integers that the user entered
4) exit the program
DO NOT use vectors!
Context:
A drop of sweat dripped from Addie's light brown hair and floated in a slow
arc towards the track. Her eyes focused on the track in front of her. It was
still disconcerting how it curved up. It was like whe was always running
inside a large hamster wheel. Well it really was a lot like that but much
bigger. The diameter of the centripetal wheel was a full kilometer. It
couldn't be any smaller than that without creating strange coriolis
effects. No matter, just having a place to run while on the ship was a huge
benefit. Addie silently thanked the designers for that foresight. And, she was
heading to Mars! How could that be bad at all?
She kept her stride as she passed the blue stripe painted across the
track. That was the lap marker and the entry point to the track. Bryce and
Vita were sitting on the floor next to the track, stretching and
talking. They'd begin their run soon. It wasn't clear if Bryce and Vita were a
'thing' or not. But it had only been three weeks since the ship left
Earth. Thirty-five more weeks to go. A lot could happen. In fact, the psychs
were worried that everyone would get stir crazy long before that. Addie didn't
think so, it was just too exciting.
The health officer required everyone to spend at least an hour on the wheel
every twenty-four hours. The track was ten meters wide so there was plenty of
room for multiple runners and walkers. On the right side of the track, every
fifty meters, were large windows facing out into the blackness of space.
1 Expert Answer

Patrick B. answered 04/06/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
typedef struct _TTimeRec
{
int min;
int sec;
long secs;
} * TTimeRec;
#define TIME_REC_SIZE (sizeof(struct _TTimeRec))
typedef struct _TTimeRec TimeRec;
typedef struct _TListNode
{
TimeRec timeRec;
struct _TListNode * next;
} * TListNode;
#define LIST_NODE_SIZE (sizeof(struct _TListNode))
typedef struct _TLinkedList
{
TListNode first;
TListNode last;
int count;
} *TLinkedList;
List_Init(TLinkedList list)
{
list->first = list->last = NULL;
list->count = 0;
}
List_Push(TLinkedList list, TTimeRec timeRec)
{
TListNode newNode = (TListNode) malloc(LIST_NODE_SIZE);
memcpy(&newNode->timeRec,timeRec,TIME_REC_SIZE);
newNode->next = NULL;
if (list->count==0)
{
list->first = list->last = newNode;
}
else
{
list->last->next = newNode;
list->last = list->last->next;
}
list->count++;
}
List_Destroy(TLinkedList list)
{
TListNode tempPtr = list->first;
for (int iLoop=0; iLoop<list->count; iLoop++)
{
list->first = list->first->next;
free(tempPtr);
tempPtr=list->first;
}
list->count=0;
}
TimeRecList2Array(TLinkedList list, TTimeRec timeRecs)
{
TListNode cur= list->first;
for (int iLoop=0; iLoop<list->count; iLoop++)
{
memcpy(&timeRecs[iLoop],&cur->timeRec,TIME_REC_SIZE);
// cout << "transferred " << timeRecs[iLoop].min << ":" << timeRecs[iLoop].sec << endl;
cur=cur->next;
}
}
TimeRecCompare(const void * rec1, const void * rec2)
{
TTimeRec timeRecPtr1 = (TTimeRec)rec1;
TTimeRec timeRecPtr2 = (TTimeRec)rec2;
long timeSecs1 = timeRecPtr1->secs;
long timeSecs2 = timeRecPtr2->secs;
int iReturn=0;
if (timeSecs1 != timeSecs2)
{
iReturn = (timeSecs1 > timeSecs2) ? 1 : -1;
}
return(iReturn);
}
Go()
{
struct _TLinkedList listTimeRecs;
List_Init(&listTimeRecs);
int iMin=-2,iSec=61;
cout << " Input -1 for BOTH minutes and seconds to complete the input....." << endl;
do
{
iMin=-2; iSec=61;
while (iMin<-1)
{
cout << "Please input # of minutes or -1 to quit :>";
cin >> iMin;
if (iMin<-1) { cout << "Invalid minutes ! " << endl; }
}
while ((iSec<-1) || (iSec>59))
{
cout << "Please input # of seconds or -1 to quit :>";
cin >> iSec;
if ((iSec<-1) || (iSec>59)) { cout << "Invalid seconds ! " << endl; }
}
if ((iMin>=0) && (iSec>=0))
{
struct _TTimeRec curTimeRec;
curTimeRec.min = iMin;
curTimeRec.sec = iSec;
curTimeRec.secs = iMin*60+iSec;
List_Push(&listTimeRecs,&curTimeRec);
}
} while ((iMin>=0) && (iSec>=0));
int N=listTimeRecs.count;
TTimeRec timeRecs = (TTimeRec)malloc(TIME_REC_SIZE*N);
TimeRecList2Array(&listTimeRecs,timeRecs);
qsort(timeRecs,N,TIME_REC_SIZE,TimeRecCompare);
long totalSumSecs = 0;
cout << " Min Sec " << endl;
for (int iLoop=0; iLoop<N; iLoop++)
{
cout << timeRecs[iLoop].min << ":" << setfill('0') << setw(2) << timeRecs[iLoop].sec;
totalSumSecs += timeRecs[iLoop].secs;
if (iLoop==0)
{
cout << " <---- FASTEST TIME " << endl;
}
else if (iLoop==N-1)
{
cout << " <---- SLOWEST TIME " << endl;
}
else
{
cout << endl;
}
}
long avgSecs = ceil(totalSumSecs/N);
cout << "-----------------------------------------------" << endl;
cout << " AVERAGE TIME " << avgSecs/60 << ":" << avgSecs%60 << endl;
free(timeRecs);
List_Destroy(&listTimeRecs);
}
int main()
{
Go();
}
Hall H.
It isn't compiling i have received the following errors: splits.cpp:54:27: error: ISO C++ forbids declaration of ‘List_Init’ with no type [-fpermissive] List_Init(TLinkedList list) ^ splits.cpp:64:45: error: ISO C++ forbids declaration of ‘List_Push’ with no type [-fpermissive] List_Push(TLinkedList list, TTimeRec timeRec) ^ splits.cpp: In function ‘int List_Push(TLinkedList, TTimeRec)’: splits.cpp:70:3: error: ‘memcpy’ was not declared in this scope memcpy(&newNode->timeRec,timeRec,TIME_REC_SIZE); ^~~~~~ splits.cpp:70:3: note: suggested alternative: ‘wmemcpy’ memcpy(&newNode->timeRec,timeRec,TIME_REC_SIZE); ^~~~~~ wmemcpy splits.cpp: At global scope: splits.cpp:96:30: error: ISO C++ forbids declaration of ‘List_Destroy’ with no type [-fpermissive] List_Destroy(TLinkedList list) ^ splits.cpp:123:54: error: ISO C++ forbids declaration of ‘TimeRecList2Array’ with no type [-fpermissive] TimeRecList2Array(TLinkedList list, TTimeRec timeRecs) ^ splits.cpp: In function ‘int TimeRecList2Array(TLinkedList, TTimeRec)’: splits.cpp:138:7: error: ‘memcpy’ was not declared in this scope memcpy(&timeRecs[iLoop],&cur->timeRec,TIME_REC_SIZE); ^~~~~~ splits.cpp:138:7: note: suggested alternative: ‘wmemcpy’ memcpy(&timeRecs[iLoop],&cur->timeRec,TIME_REC_SIZE); ^~~~~~ wmemcpy splits.cpp: At global scope: splits.cpp:151:52: error: ISO C++ forbids declaration of ‘TimeRecCompare’ with no type [-fpermissive] TimeRecCompare(const void * rec1, const void * rec2) ^ splits.cpp:186:4: error: ISO C++ forbids declaration of ‘Go’ with no type [-fpermissive] Go() ^04/13/21
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
Incomprehensible04/06/21