![]() |
|
|
|||||||
|
|||
|
|
|||
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
|
|||
|
|
#10402 (permalink) |
|
Is moving.
![]() Join Date: Aug 2004
Posts: 9,652
|
Re: The Undead Gateway Thread
My last datastructures program... pretty simple really
//********************************PROGRAM IDENTIFICATION******************************** //* * //* PROGRAM FILE NAME:Program2.cpp ASSIGNMENT #: 2 * //* * //* PROGRAM AUTHOR: ________________________________________ * //* Doug Martin * //* * //* COURSE #: CSC 360 DUE DATE: February 20th, 2006 * //* * //************************************************** ************************************ //********************************PROGRAM DESCRIPTION*********************************** //* * //* PROCESS: Read data from input file, create database of insurance policies, print * //* database or single policies when requested, and update as needed. * //* * //* USER DEFINED MODULES: * //* policyClass: sets all fields to zero * //* void print: prints all files or a single file from the database * //* int add: function that adds boarding numbers to seat charts * //* void update: changes a single field of a database file * //* void del: deletes a file from the database * //* void header: standard printed header * //* void footer: standard printed footer * //* * //************************************************** ************************************ #include <iostream.h> #include <fstream.h> #include <iomanip.h> #include <cctype> #include <cstring> class policyClass{ public: policyClass(); int add (policyClass [], ifstream &, ofstream &, int &); void del (policyClass [], ifstream &, ofstream &); void update(policyClass [], ifstream &, ofstream &); void print (policyClass [], ifstream &, ofstream &); private: int idNum; char name[21]; int value; float premium; int deduct; char plate[8]; char state[3]; int tag; }; // Function ProtoTypes void header(ofstream &); void footer(ofstream &); //************************MAIN FUNCTION****************************************** ********** void main(){ //opens data file ifstream infile("data2", ios::in); //opens output file ofstream outfile("output.txt", ios::out); //prints header header(outfile); //varible declarations for action, index and elements used char act; int eu = 0, i; policyClass database[51]; //Array of Classes instatiated //sead read of input file infile >> ws; infile.get (act); for (i = 0; i < 51; i++) { //calls desired function based on input switch (act){ case 'A': database[eu].add (database, infile, outfile, eu); break; case 'D': database[eu].del (database, infile, outfile); break; case 'P': database[eu].print (database, infile, outfile); break; case 'U': database[eu].update (database, infile, outfile); break; case 'Q': i = 51; break; } infile >> ws; infile.get (act); } footer (outfile); } //************************END OF MAIN********************************************** ******** //************************CONSTRUCTOR FUNCTION****************************************** *** policyClass::policyClass() { //sets all fields to zero idNum = 0; name[21] = 0; value = 0; premium = 0; deduct = 0; plate[8] = 0; state[3] = 0; tag = 0; } //************************END OF CONSTRUCTOR FUNCTION************************************** //************************ADD FUNCTION****************************************** *********** int policyClass::add(policyClass database[], ifstream &infile, ofstream &outfile, int &eu) { char tempName[21], tempPlate[8], tempState[3]; int tempIdNum, tempValue, tempDeduct, i, valid = 0; float tempPremium; //reads in fields from input file infile >> ws; infile >> tempIdNum; infile >> ws; infile.getline (tempName, 21, '\n'); infile >> ws; infile >> tempValue; infile >> ws; infile >> tempPremium; infile >> ws; infile >> tempDeduct; infile >> ws; infile.getline (tempPlate, 8, ' '); infile >> ws; infile.getline (tempState, 3, ' '); //test for existing file for (i= 0; i < 50; i++){ if ((database[i].idNum == tempIdNum)&& (valid == 0)){ valid = 1; outfile << "Error ! Atempt to add a duplicate record. Attempt failed! \n"; } } if (valid == 0){ idNum = tempIdNum; strcpy(name, tempName); value = tempValue; premium = tempPremium; deduct = tempDeduct; strcpy(plate, tempPlate); strcpy(state, tempState); tag = 1; //sets file tag to active //prints message of file addition outfile <<"New policy number "<<idNum<<" successfully added to the data base. \n"; eu++; } outfile << "***********************************************\n "; return eu; } //************************END OF ADD FUNCTION****************************************** **** //************************DELETE FUNCTION****************************************** ******** void policyClass::del(policyClass database[], ifstream & infile, ofstream &outfile) { int i, tempIdNum, found = 0; //attempting to find file to delete infile >> tempIdNum; for (i =0; i < 51; i++){ if (database[i].idNum == tempIdNum){ database[i].tag = 0; found = 1; //if found tag is set to 1 } } if (found == 0){ //if file is not found default message. outfile << "Attempt to delete a non existent record. Attempt failed. \n"; outfile << "***********************************************\n "; } } //************************END OF DELETE FUNCTION****************************************** * //************************PRINT FUNCTION****************************************** ********* void policyClass::print(policyClass database[], ifstream &infile, ofstream &outfile) { char action; int i, found = 0, tempIdNum; infile >> ws; infile >> action; switch (action) { //print case for Entire database. case 'E': outfile << "Printing entire data base. \n\n"; for (i = 0; i < 51; i++){ if (database[i].tag == 1){ outfile.setf(ios::left); outfile << "Policy Number: " << setw(8) << database[i].idNum <<" Policy Holder: " << setw(2) << database[i].name <<" Amount of Insurance: "<<setw(5)<< database[i].value<<endl; outfile << "Annual Premium: " <<setw(7)<< database[i].premium <<" Deductable: " <<setw (23)<< database[i].deduct <<" Licence Number: "<<setw(10)<< database[i].plate<<endl; outfile << "State of Insured: "<< database[i].state<<endl<<endl; } } break; case 'S': //print case for Single file infile >> tempIdNum; for (i = 0; i < 51; i++){ if((database[i].idNum == tempIdNum)&&(database[i].tag == 1)){ outfile << "Printing information for a single file. \n"; outfile.setf(ios::left); outfile << "Policy Number: " << setw(8) << database[i].idNum <<" Policy Holder: " << setw(2) << database[i].name <<" Amount of Insurance: "<<setw(5)<< database[i].value<<endl; outfile << "Annual Premium: " <<setw(7)<< database[i].premium <<" Deductable: " << setw (23) << database[i].deduct <<" Licence Number: " << setw(10) << database[i].plate<<endl; outfile << "State of Insured: " << database[i].state <<endl<<endl; outfile <<"*********************************************** \n"; found = 1; //if file is found tag is set to 1 } } if (found == 0){ //if no file is found message is printed outfile << "Attempt to print a non existent record. Attempt failed.\n"; } break; } } //************************END OF PRINT FUNCTION****************************************** ** //************************UPDATE FUNCTION****************************************** ******** void policyClass::update(policyClass database[], ifstream &infile, ofstream &outfile) { int i, tempIdNum, field, found = 0, tempValue, tempDeduct; char tempName[21], tempPlate[8], tempState[3]; float tempPremium; infile >> ws; infile >> tempIdNum; infile >> ws; infile >> field; //swith to set selected field for (i = 0; i < 51; i++){ if (database[i].idNum == tempIdNum){ switch (field){ case 1: infile >> ws; infile.getline (tempName, 21, '\n'); strcpy(database[i].name, tempName); outfile << "Policy Number " << tempIdNum << " updated. \n"; found = 1; break; case 2: infile >> ws; infile >> tempValue; database[i].value = tempValue; outfile << "Policy Number " << tempIdNum << " updated. \n"; found = 1; break; case 3: infile >> ws; infile >> tempPremium; database[i].premium = tempPremium; outfile << "Policy Number " << tempIdNum << " updated. \n"; found = 1; break; case 4: infile >> ws; infile >> tempDeduct; database[i].deduct = tempDeduct; outfile << "Policy Number " << tempIdNum << " updated. \n"; found = 1; break; case 5: infile >> ws; infile >> tempPlate; strcpy (database[i].plate, tempPlate); outfile << "Policy Number " << tempIdNum << " updated. \n"; found = 1; break; case 6: infile >> ws; infile >> tempState; strcpy (database[i].state, tempState); outfile << "Policy Number " << tempIdNum << " updated. \n"; found = 1; break; } outfile <<"*********************************************** \n"; } } if (found == 0){ outfile << "Attempt to update a non existent record. Attempt failed. \n"; outfile <<"*********************************************** \n"; } } //************************END OF UPDATE FUNCTION****************************************** * //************************FUNCTION HEADER******************************************** ****** void header(ofstream &outfile) { outfile << "Doug Martin "; outfile << "CSC 360 "; outfile << "Section 21 \n"; outfile << "Spring 2006 "; outfile << "Assignment #2\n"; outfile << "-----------------------------------"; outfile << "-----------------------------------\n\n"; return; } //**********************END OF HEADER FUNCTION****************************************** *** //************************FOOTER FUNCTION****************************************** ******** void footer(ofstream &outfile) { outfile <<"\tEND OF PROGRAM OUTPUT\n"; } //***********************END OF FOOTER FUNCTION****************************************** **
__________________
In wine there is wisdom, in beer there is freedom, in water there is bacteria. -Ben Franklin |
|
|
|
|
|
#10404 (permalink) | |
|
Yeay for punkins!
Join Date: Apr 2003
Posts: 5,968
|
Re: The Undead Gateway Thread
Quote:
![]()
__________________
Proud member of the ND4SPD Army! '97 Ford Exploder XLT - 200500 miles (!) '02 Mercury Cougar C2 - For Sale '05 Mini Cooper S - Race Car '06 Lincoln Zephyr - Daily driver/baby mobile |
|
|
|
|
|
|
#10406 (permalink) | |
|
is moving his car
|
Re: The Undead Gateway Thread
Quote:
appreciate - yes respect - no
__________________
1994 Lincoln Towncar w/ 112576 1996 Contour SE MTX loaded w/ 137179 1999 Silver Frost ATX original owner w/ 70500 RUNNING!!!! |
|
|
|
|
|
|
#10407 (permalink) | |
|
is moving his car
|
Re: The Undead Gateway Thread
Quote:
__________________
1994 Lincoln Towncar w/ 112576 1996 Contour SE MTX loaded w/ 137179 1999 Silver Frost ATX original owner w/ 70500 RUNNING!!!! |
|
|
|
|
|
|
#10409 (permalink) | ||
|
I hear voices...
|
Re: The Undead Gateway Thread
Quote:
__________________
Quote:
|
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
|
|||
|
|
|||