Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

not sure why it is doing this help please but only modify and update assessment.h and assessment.cpp assessment.cpp #define _CRT_SECURE_NO_WARNINGS #include Assessment.h #include namespace seneca

not sure why it is doing this help please but only modify and update assessment.h and assessment.cpp

image

assessment.cpp

#define _CRT_SECURE_NO_WARNINGS
#include "Assessment.h"
#include

namespace seneca {

   bool read(int& value, FILE* fptr) {
       return fscanf(fptr, "%d", &value) == 1;
   }

   bool read(double& value, FILE* fptr) {
       return fscanf(fptr, "%lf", &value) == 1;
   }

   bool read(char* cstr, FILE* fptr) {
       return fscanf(fptr, ",%60[^\n]\n", cstr) == 1;
   }

   bool read(Assessment& assess, FILE* fptr) {
       double tempMark;
       char tempTitle[61];

       if (fscanf(fptr, "%lf,", &tempMark) == 1 && read(tempTitle, fptr)) {
           assess.m_mark = new double;
           assess.m_title = new char[strlen(tempTitle) + 1];
           *assess.m_mark = tempMark;
           strcpy(assess.m_title, tempTitle);
           return true;
       }

       return false;
   }

   void freeMem(Assessment*& aptr, int size) {
       for (int i = 0; i < size; ++i) {
           delete aptr[i].m_mark;
           delete[] aptr[i].m_title;
       }
       delete[] aptr;
       aptr = nullptr;
   }

   int read(Assessment*& aptr, FILE* fptr) {
       int numRecords;
       if (!read(numRecords, fptr)) {
           return 0;
       }

       aptr = new Assessment[numRecords];
       int readCount = 0;

       for (int i = 0; i < numRecords; ++i) {
           if (read(aptr[i], fptr)) {
               ++readCount;
           }
           else {
               break;
           }
       }

       if (readCount != numRecords) {
           freeMem(aptr, numRecords);
           return 0;
       }

       return numRecords;
   }

} // namespace seneca
assessment.h

#ifndef ASSESSMENT_H
#define ASSESSMENT_H

#include

namespace seneca {

   struct Assessment {
       double* m_mark;
       char* m_title;
   };

   bool read(int& value, FILE* fptr);
   bool read(double& value, FILE* fptr);
   bool read(char* cstr, FILE* fptr);
   bool read(Assessment& assess, FILE* fptr);
   void freeMem(Assessment*& aptr, int size);
   int read(Assessment*& aptr, FILE* fptr);

} // namespace seneca

#endif // ASSESSMENT_H
main.cpp

#define _CRT_SECURE_NO_WARNINGS

#include
#include
#include
#include "Assessment.h"
#include "Assessment.h"
#include "Assessment.h"
using namespace seneca;
using namespace std;
void display(const Assessment& a);
bool readTesters();
int main() {
   if (readTesters()) {
       int cnt;
       Assessment* aptr = nullptr;
       FILE* fptr = fopen("baddata.txt", "r");
       cnt = read(aptr, fptr);
       if (cnt) {
           cout << "This should have failed, keep working on the workshop!" << endl;
       }
       else {
           cout << "File records and number of records do not match!" << endl;   // this is the correct output
       }
       fclose(fptr);
       cout << "Listing Good Data:" << endl;
       fptr = fopen("gooddata.txt", "r");
       cnt = read(aptr, fptr);
       if (cnt) {
           for (int i = 0; i < cnt; i++) {
               cout << (i + 1) << ": ";
               display(aptr[i]);
           }
           freeMem(aptr, cnt);
       }
       else {
           cout << "This should not have failed, keep working on the workshop!" << endl;
       }
       fclose(fptr);
   }
   return 0;
}
void display(const Assessment& a) {
   cout.setf(ios::fixed);// setting the number of digits
   cout.precision(1);    // after the decimal point to 1
   // this will be covered later
   cout << a.m_title << ": " << *a.m_mark << endl;
}

bool readTesters() {
   FILE* fptr = fopen("gooddata.txt", "r");
   bool passed = true;
   int i;
   double d;
   char str[61];
   if (read(i, fptr) && i == 13) {
       cout << "bool read(int& value, FILE* fptr) test passed" << endl;
   }
   else {
       cout << "bool read(int& value, FILE* fptr) test failed" << endl;
       passed = false;
   }
   if (passed && read(d, fptr) && (d - 70.9) < 0.0001 && (d - 70.9) > -0.0001) {
       cout << "bool read(double& value, FILE* fptr) test passed" << endl;
   }
   else {
       cout << "bool read(double& value, FILE* fptr) test failed" << endl;
       passed = false;
   }
   if (passed && read(str, fptr) && strcmp(str, "Applied Problem Solving") == 0) {
       cout << "bool read(double& value, FILE* fptr) test passed" << endl;
   }
   else {
       cout << "bool read(double& value, FILE* fptr) test failed" << endl;
       passed = false;
   }
   fclose(fptr);
   return passed;
}

0 File 99 % Edit View Git 1- & AA 5. main.cppX Assessment.h p1 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 18 Project Build Debug Test Analyze Debug x64 Assessment.cpp 8 A Extensions Window Help Local Windows Debugger - - else { cout < < < "bool read (int& value, FILE* fptr) test failed" < < endl; passed= false; Tools (Global Scope) else { cout < < "bool read(double& value, FILE* fptr) test failed" < < endl; passed = false; fclose(fptr); return passed; if (passed && read(d, fptr) && (d - 70.9) < 0.0001 && (d - 70.9) > -0.0001) { cout < < < < "bool read(double& value, FILE* fptr) test passed" < < endl; No issues found else { cout < < < "bool read(double& value, FILE* fptr) test failed" passed = false; if (passed && read(str, fptr) && strcmp(str, "Applied Problem Solving") == 0) { cout < < < "bool read(double& value, FILE* fptr) test passed" Microsoft Visual Studio Error List Immediate Window Output Build succeeded Output Show output from: Build 1>p1.vcxproj-> C:\Users\balit\OneDrive\Desktop\00P244\w2\p1\x64\Debug\p1.exe ========== Build: 1 succeeded, 0 failed, up-to-date, skipped ========== ========== Build completed at 10:54 AM and took 00.510 seconds ========== Please consider donating to VSColorOutput https://mike-ward.net/donate/ (this message can be turned off in the settings panel) Search c Lo 5 X abc p1 Unable to start program CE Q; read Testers() C:\Users\balit\OneDrive\Desktop\OOP244\w2\p1\x64\Debug\ p1.exe'. Operation did not complete successfully because the file contains a virus r potentially unwanted software. 8 OK Ln: 94 Ch: 2 SPC CRLF Solution Explorer 06 Search Solution Explorer (Ctrl+;) Solution 'p1' (1 of 1 project) p1 - References Sign in t PEAL External Dependencies Header Files Assessment.h Resource Files Source Files ++ Assessment.cpp ++ main.cpp Solution Explorer Git Changes Class View Properties Add to Source Control O Windows Security Windows Security x - O. - x Threats found Microsoft Defender Antiviru details. Dism

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Analytics Data Analysis And Decision Making

Authors: S. Christian Albright, Wayne L. Winston

7th Edition

0357109953, 978-0357109953

More Books

Students also viewed these Algorithms questions

Question

Find the frequency of green light with a wavelength of 555 nm.

Answered: 1 week ago