Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* The requirements are to use char arrays for string data but this program uses std::string. * The requirements say that you cannot use continue

* The requirements are to use char arrays for string data but this program uses std::string.
* The requirements say that you cannot use "continue" but this is in the main loop in main.cpp
* The insertData() function doesn't parse the input line
* The insertData() function doesn't place items into the array
* The output format of printReport() is incorrect
main.cpp:
#include
#include
#include "functions.h"
#include "assignment.h"
using namespace std;
int main(int argc, char *argv[]){
if (argc !=2){
cerr << "Usage: "<< argv[0]<<""<< endl;
return 1;
}
ifstream file(argv[1]);
if (!file.is_open()){
cerr << "Error opening file." << endl;
return 1;
}
Assignment assignments[MAX_ASSIGNMENTS];
int numAssignments =0;
string line;
while (getline(file, line)){
if (line.empty()|| line[0]=='#'){
continue; // Skip empty lines and comments
}
insertData(assignments, numAssignments, line);
}
file.close();
printReport(assignments, numAssignments);
return 0;
}
functions.cpp:
#include "functions.h"
#include
void insertData(Assignment assignments[], int& numAssignments, const std::string& line){
// Placeholder implementation
// Extract data from the line and insert it into the assignments array
// For now, let's just print the line to simulate inserting data
std::cout << "Inserting data: "<< line << std::endl;
// Increment numAssignments for the next assignment
numAssignments++;
}
void printReport(const Assignment assignments[], int numAssignments){
// Placeholder implementation
// Print report based on the assignments array
std::cout << "Printing report..." << std::endl;
for (int i =0; i < numAssignments; ++i){
// Print each assignment
std::cout << "Assignment "<< i +1<<": "<< assignments[i].day <<","
<< assignments[i].task <<","<< assignments[i].who << std::endl;
}
}
assignment.h:
#ifndef ASSIGNMENT_H
#define ASSIGNMENT_H
#include // Add this line
const int MAX_ASSIGNMENTS =100;
struct Assignment {
int day;
std::string task; // Use "std::string" instead of just "string"
std::string who; // Use "std::string" instead of just "string"
};
#endif // ASSIGNMENT_H
functions.h:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include "assignment.h"
#include
void insertData(Assignment assignments[], int& numAssignments, const std::string& line);
void printReport(const Assignment assignments[], int numAssignments);
#endif // FUNCTIONS_H

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

Google Analytics 4 The Data Driven Marketing Revolution

Authors: Galen Poll

2024th Edition

B0CRK92F5F, 979-8873956234

More Books

Students also viewed these Databases questions

Question

Discuss the history of human resource management (HRM).

Answered: 1 week ago