NECO Forums

Go Back   NECO Forums > Chapters > Gateway NECO

Sponsored Links: Want to make these ads disappear? Become a "Gold Member" or "Platinum Member" and they will!

Reply
 
LinkBack Thread Tools Display Modes
Old 02-27-2006, 05:25 PM   #10401 (permalink)
is moving his car
Lifetime Platinum MemberModerator
 
bensenvill's Avatar
 
Join Date: Aug 2003
Location: Chicago
Posts: 13,274
Blog Entries: 4
Re: The Undead Gateway Thread

I mean how could it be any easier!
__________________
1994 Lincoln Towncar w/ 112576
1996 Contour SE MTX loaded w/ 137179
1999 Silver Frost ATX original owner w/ 70500 RUNNING!!!!
bensenvill is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links: Want to make these ads disappear? Become a "Gold Member" or "Platinum Member" and they will!
Old 02-27-2006, 05:28 PM   #10402 (permalink)
Is moving.
Moderator
 
Moraki's Avatar
 
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
Moraki is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:30 PM   #10403 (permalink)
Is moving.
Moderator
 
Moraki's Avatar
 
Join Date: Aug 2004
Posts: 9,652
Re: The Undead Gateway Thread

Wow this bulletin really kills the proper indenting and spaces.
__________________
In wine there is wisdom, in beer there is freedom, in water there is bacteria. -Ben Franklin
Moraki is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:35 PM   #10404 (permalink)
Yeay for punkins!
Lifetime Platinum MemberModerator
 
tnkgurl's Avatar
 
Join Date: Apr 2003
Posts: 5,968
Re: The Undead Gateway Thread

Quote:
Originally Posted by bensenvill
you gotta love java for **** like this... properly formatting a date

try {
GregorianCalendar cal = new GregorianCalendar();
DecimalFormat df = new DecimalFormat("00");
String timestamp = cal.get(GregorianCalendar.YEAR) + "-" + df.format(cal.get(GregorianCalendar.MONTH) + 1) + "-" + df.format(cal.get(GregorianCalendar.DAY_OF_MONTH)) + " " + df.format(cal.get(GregorianCalendar.HOUR_OF_DAY)) + ":" + df.format(cal.get(GregorianCalendar.MINUTE)) + ":" + df.format(cal.get(GregorianCalendar.SECOND));
FileWriter logWriter;
logWriter = new FileWriter(logfile, true);
logWriter.write(timestamp + " >>> " + message + "\n");
logWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
Dude, Terry that's perfect! One of the next projects that I have is to write a Gregorian Calendar!!!
__________________
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
tnkgurl is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:39 PM   #10405 (permalink)
I hear voices...
Lifetime Platinum MemberModerator
 
sonza68's Avatar
 
Join Date: Jan 2001
Location: Chesterfield, MO
Posts: 13,765
Images: 14
Blog Entries: 2
Re: The Undead Gateway Thread

You guys are making me appreciate visual basic a lot more.
__________________
Quote:
Originally Posted by BigBalledOX
It's never a good time for pants.
Ask Ov3n about his adjustable knob.
sonza68 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:52 PM   #10406 (permalink)
is moving his car
Lifetime Platinum MemberModerator
 
bensenvill's Avatar
 
Join Date: Aug 2003
Location: Chicago
Posts: 13,274
Blog Entries: 4
Re: The Undead Gateway Thread

Quote:
Originally Posted by sonza68
You guys are making me appreciate visual basic a lot more.

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!!!!
bensenvill is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:54 PM   #10407 (permalink)
is moving his car
Lifetime Platinum MemberModerator
 
bensenvill's Avatar
 
Join Date: Aug 2003
Location: Chicago
Posts: 13,274
Blog Entries: 4
Re: The Undead Gateway Thread

Quote:
Originally Posted by tnkgurl
Dude, Terry that's perfect! One of the next projects that I have is to write a Gregorian Calendar!!!
yup, and you'll learn to hate that type of stuff. Java takes a very easy task like "what is the date" and makes it really complicated and convoluted.
__________________
1994 Lincoln Towncar w/ 112576
1996 Contour SE MTX loaded w/ 137179
1999 Silver Frost ATX original owner w/ 70500 RUNNING!!!!
bensenvill is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:55 PM   #10408 (permalink)
is moving his car
Lifetime Platinum MemberModerator
 
bensenvill's Avatar
 
Join Date: Aug 2003
Location: Chicago
Posts: 13,274
Blog Entries: 4
Re: The Undead Gateway Thread

like if it was SQL, the equivalent would be "GETDATE()"
__________________
1994 Lincoln Towncar w/ 112576
1996 Contour SE MTX loaded w/ 137179
1999 Silver Frost ATX original owner w/ 70500 RUNNING!!!!
bensenvill is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 05:56 PM   #10409 (permalink)
I hear voices...
Lifetime Platinum MemberModerator
 
sonza68's Avatar
 
Join Date: Jan 2001
Location: Chesterfield, MO
Posts: 13,765
Images: 14
Blog Entries: 2
Re: The Undead Gateway Thread

Quote:
Originally Posted by bensenvill
appreciate - yes
respect - no
It does what I need it to, and it actually resembles English.
__________________
Quote:
Originally Posted by BigBalledOX
It's never a good time for pants.
Ask Ov3n about his adjustable knob.
sonza68 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-27-2006, 06:16 PM   #10410 (permalink)
is moving his car
Lifetime Platinum MemberModerator
 
bensenvill's Avatar
 
Join Date: Aug 2003
Location: Chicago
Posts: 13,274
Blog Entries: 4
Re: The Undead Gateway Thread

http://www.break.com/index/hispeedcarcrash75.html
__________________
1994 Lincoln Towncar w/ 112576
1996 Contour SE MTX loaded w/ 137179
1999 Silver Frost ATX original owner w/ 70500 RUNNING!!!!
bensenvill is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes


Sponsored Links: Want to make these ads disappear? Become a "Gold Member" or "Platinum Member" and they will!


All times are GMT -4. The time now is 09:23 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 RC5