How do I delete a certain record?

How do I add a delete code so it deletes a record?
Here is my entire code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "medPing.h"
#include <cassert>
#include <chrono>
#include <thread>
#include <ctime>
#include <windows.h>

const long MAX_HISTORY  = 5;	// can store upto (last) MAX_HISTORY sets of vital signs

const long MAX_WAIT_SEC = 4;	// will random pause from 1 to MAX_WAIT_SEC 


struct oneVitalHistoryRecord
{
    double	bodyTemp_F; // The structure of body temperature.
    short	pulseRate; // The structure of pulse rate.
    long  nSecs; // The structure of seconds.
    short dia; // The structure of diastolic.
    short sys; // The structure of systolic.

};
//========================================

// function prototypes for keeping track of HISTORY
// (see bottom of this file where you'll write the definitions)

void AddHistoryRecord(long nSecs, // The prototype function for AddHistoryRecord.
                      double new_mp_bodyTemp_F,
                      short  new_mp_pulseRate,
                      short sys,
                      short dia,
        // you need more vital signs here

                      oneVitalHistoryRecord vitalHistory[ ],
                      long& hmr
);
long FindDateTime() { // The prototype function for FindDateTime.
    time_t rawtime;
    time(&rawtime);
    printf("\t The current local time is: %s", ctime(&rawtime));
    return 0;
}
const long NOT_FOUND = -1;  // used to indicate failure on linear search
long FindVitalRecord(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr, long del);

void DeleteHistoryRecord(oneVitalHistoryRecord* vitalHistory)
{
   delete vitalHistory;
}

void printAllVitalRecords(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr);
// end function prototypes



//-----------------------------------------------------------------------
//create a medPing object (mP object has global file scope)
medPing mP; // The medPing object.

//--------------
// medPing_Main \
//----------------------------------------------------------------------
// called from iPhone runSim-tab
int medPing_Main() // The program.
{
    // print a message to the cell phone
    mP.CELL_PrintF("Hello medPing patient ...\n\n");

    //======= DATA STRUCTURE ======================================
    // to hold patient's history of vital signs
    oneVitalHistoryRecord	vitalHistory[MAX_HISTORY];

    // hmr (how many really) vital signs  0 <= hmr < MAX_HISTORY
    long hmr = 0;
    //=============================================================

    RandGen		randGenerator;	// i need a random number generator // Our random generator for the program to use for the data.
    time_t		start, now;		// keep track of time in simulation // Our time vital sign.


    // ask user at CELL to input length of simulation
    mP.CELL_PrintF("How many SECONDS would you like to simulate?\n"); // Asks the user to type in an amount of seconds for the program to run.
    double simulationTime = mP.CELL_fetchReal();
    time(&start);

    // simulation loop ....
    time(&now);
    while ( difftime(now,start) < simulationTime )		// while still time to simulate ...
    {
        long waitThisLongSEC = randGenerator.RandInt(1, MAX_WAIT_SEC);
        mP.CELL_PrintF("\n--------------------------\n");
        mP.CELL_PrintF("\n[PAUSE ... (%d seconds) ]\n", waitThisLongSEC);
        std::this_thread::sleep_for(std::chrono::milliseconds(waitThisLongSEC*1000));
        // sleep(waitThisLongSEC);	// ZZzzzz.....
        // WINDOWS uses the function called: Sleep( milliseconds )
        // Sleep(waitThisLongSEC*1000);	// ZZzzzz.....



        // check our watch ...
        long nSecs = time(&now); // The function that checks the seconds.

        // fetch vital signs from the medPing chip HERE (use mP object)
        double newTemp; // The vital sign for a new temperature.
        newTemp = mP.getBodyTemperature_F();

        short newPulseRate; // The vital sign for a new pulse rate.
        newPulseRate = mP.getPulseRate_BPM();

        short sys, dia; // The vital signs for systolic and dissystolic
        mP.getBloodPressure_mmHg(sys, dia);

        // :
        // :


        // once medPing has given you all the vital signs (see above)
        // now ADD these new vital signs to our history DATA STRUCTURE
        AddHistoryRecord(nSecs, newTemp, newPulseRate, sys, dia, vitalHistory, hmr); //Vital signs for the data structure.

                // PRINT ALL of the series of vital signs so far
        printAllVitalRecords(mP, vitalHistory, hmr); // Vital signs for printing.



    } // while still more to simulate ...


    mP.CELL_PrintF("\n\nSIMULATION OVER.\n\n"); // Lets the user know that the record counter has ended.

    // prompt for a record to delete HERE,

    mP.CELL_PrintF("What record do you want to delete?\n"); // Asks the user to type in a raw time of a record for it to delete said record.
    long del;
    del = mP.CELL_fetchInteger();
    long whichBox;
    whichBox = FindVitalRecord(mP, vitalHistory, hmr, del);
    int i;
    if(del == vitalHistory[i].nSecs)

        return i;


    // find it (using your Find function)



    // and delete it if found (using your Delete function)





    mP.CELL_PrintF("\n\nDONE.\n");

    // WINDOWS
    // system("PAUSE");

    return 0;

} // end medPing_Main()


// helpful HISTORY functions below


void AddHistoryRecord(long secs, double newTemp, short newPulseRate, short sys, short dia,
                      oneVitalHistoryRecord vitalHistory[ ],
                      long& hmr ) // The function for adding a history record.
{
    vitalHistory[hmr].bodyTemp_F = newTemp; // The variable for a new temperature.
    vitalHistory[hmr].nSecs = secs; // The variable for the amount of seconds.
    vitalHistory[hmr].pulseRate = newPulseRate; // The variable for a new pulse rate.
    vitalHistory[hmr].sys = sys; // The variable for systolic.
    vitalHistory[hmr].dia = dia; // The variable for dissystolic.

    hmr++;
}

long FindVitalRecord(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr, long del)
{
    mP.CELL_PrintF("\t I am about to delete this record.    \t%ld\n", del);
}

//---------------------\
// printAllVitalRecords \
//---------------------------------------------------------------------------------------------
// Prints history (last set of) hmr vital signs (to medPing output)
// PRE: nSecs(assigned) with a result of time() function and
//hmr(assigned) and 0 <= hmr < MAX_HISTORY and
//oneVitalHistoryRecord[0..(hmr-1)](assigned)
// POST: if nSecs found within oneVitalHistoryRecord[]
//then RETURNS index of array cell where found
//otherwise RETURNS “NOT_FOUND” (constant indicating “not found”
// SIDE EFFECTS:
//---------------------------------------------------------------------------------------------
void printAllVitalRecords(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr) // Void for printing all of the Vital Record data.
{
    if (hmr > 0)
    {
        mP.CELL_PrintF("\n---- Records (so far) ----"); // Displays above all the records.
        for(long i=0; i < hmr; i++)
        {
            mP.CELL_PrintF("\nRECORD [%02d]\n", i); // Prints the title for the record.
            mP.CELL_PrintF("\t raw time:    \t%4d\n", vitalHistory[i].nSecs); // Prints the raw time for the record.
            mP.CELL_PrintF(reinterpret_cast<const char *>(FindDateTime())); // Prints the date and time for the record.
            mP.CELL_PrintF("\t temp(F):    \t%4.1f\n", vitalHistory[i].bodyTemp_F); // Prints the temperature for the record.
            mP.CELL_PrintF("\t pulse(BPM): \t%4d\n",   vitalHistory[i].pulseRate); // Prints the pulse rate for the record.
            mP.CELL_PrintF("\t Systolic:    \t%4d\n", vitalHistory[i].sys); // Prints the systolic for the record.
            mP.CELL_PrintF("\t Diasystolic:   \t%4d\n", vitalHistory[i].dia); // Prints the dissystolic for the record.

        } // for all records so far
        mP.CELL_PrintF("\n---- end History ----\n\n"); // When the program is finished with the records.

    } // if any records
    else
        mP.CELL_PrintF("\nNo History so far ...\n\n"); // Incase the code doesn't work.

} // printAllVitalRecords() 


The output is supposed to look like this.
RECORD [00]
raw time: 1233286115
Local time and date: Thu Jan 29 19:28:35 2009
temp(F): 98.6
pulse(BPM): 86
RECORD [01]
raw time: 1233286119
Local time and date: Thu Jan 29 19:28:39 2009
temp(F): 100.1
pulse(BPM): 83
DELETE a record; Enter a RAW TIME: 1233286119
(Now show all remaining records after delete)
------------------------------
RECORD [00]
raw time: 1233286115
Local time and date: Thu Jan 29 19:28:35 2009
temp(F): 98.6
pulse(BPM): 86
Last edited on
Lets have array with five elements:
{ 9, 3, 4, 8, 6 }

You are supposed to find 4 from it. It is there, at index 2:
{ 9, 3, 4, 8, 6 }
        ^

What we can do, is copy everything that is after the target one element left. That is 8 and 6:
{ 9, 3, 4, 8, 6 }
// copy the 8
{ 9, 3, 8, 8, 6 }
// copy the 6
{ 9, 3, 8, 6, 6 }

Now the array has four elements.
Job done.

Last edited on
So where do I put the code.
If you wrote this code, you wouldn’t ask.

If you didn’t then dump it and copy it off somebody who does, because regrettably what you have is in need of a very extensive rewrite.
Bro all I know is that this code was a template and the goal is to complete it. I have done EVERYTHING besides the deleting part correctly and the way it was supposed to be done. What do I have to do to get the code?
Last edited on
All you have to do is write it yourself. However, if you have a specific problem with your attempt code, or even you attempt pseudocode, then show us and describe it, Bro.
Bruh I tried and it never works. Please atleast give me a starting code.
First step is to explain to me what a record is, and how/where each one is saved. If the answer is each record is stored in an array of records, deleting one is the same process as @keskiverto has shown, Bruh.
Last edited on
Then please type the code :(
if you don't care about order:
want to delete element 4 at index 2
{ 9, 3, 4, 8, 6 }
        ^

replace it with the last element (in this case 6 at index 4)
{ 9, 3, 6, 8, 6 }

reduce size by 1


> So where do I put the code.
perhaps in the «DeleteHistoryRecord» function
What I mean is what is the code?
Then please type the code :(
What I mean is what is the code?

Everybody here knows what you mean, Bruh.

What you in turn need to understand is what we mean - i.e you write the code as your best attempt or show an indication that you are, then show us what you have and where you need assistance, and ... bingo! ... you will be flooded with help and suggestions from a whole host of decent people, keen for you to become the best C++ programmer in the universe, Bruh.

Believe me, experience shows from tens of thousands of comments and questions and happy 'customers' this is by far the best and quickest way for you to get to your goal using this site, Bro.

You have to trust in your own ability and eagerness to learn otherwise you're just going to be pushed around for the rest of your life, Bro.
WrestleZero wrote:
all I know is that this code was a template and the goal is to complete it.
What do I have to do to get the code?

You get code by writing it.
The goal is that you know enough about C++ to be able to complete the program.

If you can't write code, then you have to admit that you don't know enough, yet. Time to read the course material again and/or discuss with the teacher.
Last edited on
It would be much better if vitalHistory was a std::vector and not a c-style array.
Topic archived. No new replies allowed.