Ask a question from expert

Ask now

Error Checking And Handling

12 Pages2453 Words21 Views
   

Added on  2022-09-06

Error Checking And Handling

   Added on 2022-09-06

BookmarkShareRelated Documents
Running head: INHERITANCE AND FILE HANDLING IN C++
INHERITANCE AND FILE HANDLING IN C++
Name of the Student
Name of the University
Author Note
Error Checking And             Handling_1
INHERITANCE AND FILE HANDLING IN C++1
Table of Contents
Instruction on using the program:..............................................................................................2
Code...........................................................................................................................................2
Outputs.......................................................................................................................................8
Error Checking And             Handling_2
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
Error Checking And             Handling_3
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: ";
Error Checking And             Handling_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
new features of this C++ programming
|12
|1032
|16

OOPS Concepts: C++
|10
|1216
|314

Word Puzzle Generator in C++
|8
|2069
|314

Object Oriented Programming with Java
|9
|1142
|153

C Programming Language Assignment
|44
|2042
|197

The Java Programming Document
|19
|2557
|43