Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use you project 1 (or similar one that you wrote) with header and cpp in same file to write data to a random access (binary)

Use you project 1 (or similar one that you wrote) with header and cpp in same file to write data to a random access (binary) file. Also include a program that reads the file. Please note that instead of string you need to use array of characters. See "writing to binary" and "reading from binary" examples.

This is my Code:

Headfile Data.h

#include #include using namespace std;

class data { char name1[20], name2[20], name3[20], name4[20], name5[20]; float sal1, sal2, sal3, sal4, sal5; int h_year1, h_year2, h_year3, h_year4, h_year5; int year, years[5], i; public: void setNames(char na1[], char na2[], char na3[], char na4[], char na5[]) { strcpy_s(name1, na1); strcpy_s(name2, na2); strcpy_s(name3, na3); strcpy_s(name4, na4); strcpy_s(name5, na5); } void setSalaries(float sa1, float sa2, float sa3, float sa4, float sa5) { sal1 = sa1; sal2 = sa2; sal3 = sa3; sal4 = sa4; sal5 = sa5; } void setHire_years(int y1, int y2, int y3, int y4, int y5) { h_year1 = y1; h_year2 = y2; h_year3 = y3; h_year4 = y4; h_year5 = y5; } void year_person_hired() { year = 2017; i = 0; years[i++] = year - h_year1; years[i++] = year - h_year2; years[i++] = year - h_year3; years[i++] = year - h_year4; years[i++] = year - h_year5; } void print_data() { cout << "Person Name Salary Hire_date Years since person hired" << endl; cout << name1 << "\t\t" << sal1 << "\t\t" << h_year1 << "\t\t" << years[0] << endl; cout << name2 << "\t\t" << sal2 << "\t\t" << h_year2 << "\t\t" << years[1] << endl; cout << name3 << "\t\t" << sal3 << "\t\t" << h_year3 << "\t\t" << years[2] << endl; cout << name4 << "\t\t" << sal4 << "\t\t" << h_year4 << "\t\t" << years[3] << endl; cout << name5 << "\t\t" << sal5 << "\t\t" << h_year5 << "\t\t" << years[4] << endl; } };

CPP.

#include #include #include "data.h"

using namespace std;

int main() { int setNames; int setSalaries; int setHire_years; int DTSETNAMES; int DTSETSALARIES; data dt; char names[5][10]; float sal[5]; int y[5], i; cout << "Enter Names of 5 Persons" << endl; for (i = 0; i < 5; i++) cin >> names[i];

dt.setNames(names[0], names[1], names[2], names[3], names[4]); cout << "Enter Salaries of 5 Persons" << endl; for (i = 0; i < 5; i++) cin >> sal[i];

dt.setSalaries(sal[0], sal[1], sal[2], sal[3], sal[4]); cout << "Enter Hire_dates of 5 Persons" << endl; for (i = 0; i < 5; i++) cin >> y[i]; return 0; };

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions