Error Checking And Handling
Added on 2022-09-06
12 Pages2453 Words21 Views
|
|
|
Running head: INHERITANCE AND FILE HANDLING IN C++
INHERITANCE AND FILE HANDLING IN C++
Name of the Student
Name of the University
Author Note
INHERITANCE AND FILE HANDLING IN C++
Name of the Student
Name of the University
Author Note
![Error Checking And Handling_1](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fiw%2Fd679130904b1487bb2f09b5a38057c9b.jpg&w=3840&q=10)
INHERITANCE AND FILE HANDLING IN C++1
Table of Contents
Instruction on using the program:..............................................................................................2
Code...........................................................................................................................................2
Outputs.......................................................................................................................................8
Table of Contents
Instruction on using the program:..............................................................................................2
Code...........................................................................................................................................2
Outputs.......................................................................................................................................8
![Error Checking And Handling_2](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fmh%2F597b4037cb864054a066e21db87dc305.jpg&w=3840&q=10)
INHERITANCE AND FILE HANDLING IN C++2
Instruction on using the program:
The program can be run from any computer that has gcc installed in it. Even light IDE
(Integrated development environment) like Code Blocks can also be used. One thing that
should be considered is, during the first run if you wish to view the results, then the csv
(deviceService.csv) file must be kept in the same folder to that of the running program
otherwise an error message will be displayed stating “File not found”. On the oyher hand if
you wish to create the csv file from the beginning, then there is no need to keep the supplied
csv file in the ‘.cpp’ file location. Upon going through data insertion process properly, the csv
file will be automatically created by the code.
If you want to open the visual studio project and run the program there, then latest
version of Visual Studio is preferred (Visual Studio 2019) with C++ installed in it.
Following are the written codes and outputs with some error handling:
Code
#include <iostream>
#include <string>
#include<fstream>
#include<stdlib.h>
using namespace std;
//*********************************************** FIRST CLASS
int getNumberOfDays(int month, int year);
class Device
{
public:
string DeviceDescription;
string DeviceModel;
int DeviceSerialNumber;
};
//*********************************************** SECOND CLASS
class Service
{
public:
string ServiceDescription;
int ServiceMonthGap; //No. of Month between two service
int RecentServiceDate, RecentServiceMonth, RecentServiceYear; //Recent
Service date
Instruction on using the program:
The program can be run from any computer that has gcc installed in it. Even light IDE
(Integrated development environment) like Code Blocks can also be used. One thing that
should be considered is, during the first run if you wish to view the results, then the csv
(deviceService.csv) file must be kept in the same folder to that of the running program
otherwise an error message will be displayed stating “File not found”. On the oyher hand if
you wish to create the csv file from the beginning, then there is no need to keep the supplied
csv file in the ‘.cpp’ file location. Upon going through data insertion process properly, the csv
file will be automatically created by the code.
If you want to open the visual studio project and run the program there, then latest
version of Visual Studio is preferred (Visual Studio 2019) with C++ installed in it.
Following are the written codes and outputs with some error handling:
Code
#include <iostream>
#include <string>
#include<fstream>
#include<stdlib.h>
using namespace std;
//*********************************************** FIRST CLASS
int getNumberOfDays(int month, int year);
class Device
{
public:
string DeviceDescription;
string DeviceModel;
int DeviceSerialNumber;
};
//*********************************************** SECOND CLASS
class Service
{
public:
string ServiceDescription;
int ServiceMonthGap; //No. of Month between two service
int RecentServiceDate, RecentServiceMonth, RecentServiceYear; //Recent
Service date
![Error Checking And Handling_3](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fqa%2F037120d54a854704b69b442c09fc1573.jpg&w=3840&q=10)
INHERITANCE AND FILE HANDLING IN C++3
int NextServiceDate, NextServiceMonth, NextServiceYear; //auto
calculated from ServiceMonth and LastService
};
//***************************************************** THIRD CLASS
class ServicableDevice :public Device, Service
{
public:
int choice, devices;
// File read/write
string ServiceDescription; //file handling + many parts left
ServicableDevice()
{
cout << "Check Device Service Details \n" << endl;
cout << "Enter the choice \n"
<< "1. To input the device data\n"
<< "2. To search the device data using its serial no and
display all its record\n"
<< "3. searching using specific date\n"
<< "4. To exit\n" << endl;
cout << "Enter your choice: ";
cin >> choice;
if (choice > 0 && choice <= 4)
{
if (choice == 1)
{
cout << "How many devices you want to enter: ";
cin >> devices;
int i = 0;
create(devices, i);
}
else if (choice == 2)
{
displaySerial();
}
else if (choice == 3)
{
displayNSD();
}
else
exit(0);
}
else
{
cout << "Invalid choice Try Again!!...\n" << endl;
ServicableDevice();
}
}
string DD, SD, DM;
int DSN, NM, RSY, RSM, RSD, NSY, NSM, NSD;
int flag = 0;
//************************************************************* DATA
INSERTION
void create(int num, int i)
{
for (i; i < num; i++)
{
cout << "Entry " << i + 1 << endl << endl;
cout << "Enter Device description with no space in between:
";
cin >> DD;
cout << "Enter Device Model: ";
int NextServiceDate, NextServiceMonth, NextServiceYear; //auto
calculated from ServiceMonth and LastService
};
//***************************************************** THIRD CLASS
class ServicableDevice :public Device, Service
{
public:
int choice, devices;
// File read/write
string ServiceDescription; //file handling + many parts left
ServicableDevice()
{
cout << "Check Device Service Details \n" << endl;
cout << "Enter the choice \n"
<< "1. To input the device data\n"
<< "2. To search the device data using its serial no and
display all its record\n"
<< "3. searching using specific date\n"
<< "4. To exit\n" << endl;
cout << "Enter your choice: ";
cin >> choice;
if (choice > 0 && choice <= 4)
{
if (choice == 1)
{
cout << "How many devices you want to enter: ";
cin >> devices;
int i = 0;
create(devices, i);
}
else if (choice == 2)
{
displaySerial();
}
else if (choice == 3)
{
displayNSD();
}
else
exit(0);
}
else
{
cout << "Invalid choice Try Again!!...\n" << endl;
ServicableDevice();
}
}
string DD, SD, DM;
int DSN, NM, RSY, RSM, RSD, NSY, NSM, NSD;
int flag = 0;
//************************************************************* DATA
INSERTION
void create(int num, int i)
{
for (i; i < num; i++)
{
cout << "Entry " << i + 1 << endl << endl;
cout << "Enter Device description with no space in between:
";
cin >> DD;
cout << "Enter Device Model: ";
![Error Checking And Handling_4](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fad%2F983222360c0542a69032b0f049707597.jpg&w=3840&q=10)
End of preview
Want to access all the pages? Upload your documents or become a member.
Related Documents