All pastes #40974 Raw Edit

Miscellany

public cpp v1 · immutable
#40974 ·published 2006-02-10 04:47 UTC
rendered paste body
/****************************************************************************** * Assignment 2 * Course:          OOP244 * Family Name:     Hearsum * Given Name:      Ben * Student Number:  047-687-991 * Login Name:      bjhearsu * Professor:       Ian Tipson * Due Date:        February 17, 2006 * Last Modified:   January 27, 2006 * * I declare that the attached assignment is my own work in accordance with * Seneca Academic Policy. No part of this assignment has been copied manually * or electronically from any other source (including web sites) or distributed * to other students. *****************************************************************************/#include <stdio.h>#include <string.h>#include "Account.h"/* removes an element of a string at 'pos' */void pushString(char s[], int pos) {    int i = pos;    int len = strlen(s);    for(; i < len; i++) {        s[i] = s[i+1];    }}/* removes extra whitespace from strings. * * "this   is  \t\na test\n\n" becomes:   * * "this is a test" */int oneSpace(char s[]) {    /* iterators */    int i = 0;    int len = strlen(s);    /* convert the \t and \n to spaces first */    for(; i < len; i++) {        if(s[i] == '\n' || s[i] == '\t') {            s[i] = ' ';        }    }    /* get rid of leading whitespace... */    i = 0;    while(s[i] == ' ' && s[i] != '\0') {        pushString(s, 0);    }    /* ...and trailing whitespace... */    i = strlen(s) - 1;    while(s[i] == ' ' && i != 0) {        pushString(s, i);        i--;    }    /* ...and extra spaces */    len = strlen(s);    for(i = 0; i < len; i++) {       if(s[i] == ' ' && s[i+1] == ' ') {            pushString(s, i);            /* the string is shorter, the iterator needs to be moved back */            i--;        }    }    /* return the length of it */    return strlen(s);}/* this is used by some of the accessor functions to extract information * from the customer string. */void Account::extractInfo(char st[], int field) {    int i = 0;    strcpy(st, customer);    int len = strlen(st);    /* field needs to be positive, otherwise what the heck is it looking for?     */    if(field) {        /* if we're looking for the first record..do this once         * the second, do it twice, etc         */        for(i = 0; i < field; i++) {            while(st[0] != ',') {                pushString(st, 0);            }            pushString(st, 0);        }    }    len = strlen(st);    /* find the next comma or the end of the record and write a null byte on it     */    for(i = 0; i < len; i++) {        if(st[i] == ',' || st[i] == ';') {            st[i] = '\0';        }    }}/* initializes an account with the data given */void Account::init(char c[], char num[], int b) {    changeCustomerInfo(c);    changeAccountNumber(num);    changeBalance(b);}/* changes only the customer variable */int Account::changeCustomerInfo(char c[]) {    /* holds any characters over 250 in the string */    int excess_chars = 0;    int i;    oneSpace(c);    /* copy up to 250 characters... */    for(i = 0; i < 250 && c[i] != '\0'; i++) {        customer[i] = c[i];    }    /* terminate it */    customer[i] = '\0';    /* if the string is less than 250, return 0, otherwise, returns excess */    excess_chars = strlen(c) <= 250 ? 0 : strlen(c) - 250;        return excess_chars;}