Advanced C++ Intimidation

| | Comments (0)

This evening I ran back over my old assignments from my first attempt at Advanced C++ (CSC234) been rereading the original lab I got stuck on that forced the withdraw (well... that lab and the OTHER 18 credit hours [21 total] I was taking at the time). It was a fairly simple lab, just play with some bank tellers, some customers and a few timers, that's it. A simple, straight forward modeling program. Unfortunately, the lab still scares me and my own original source code makes no sense. I am likely to take a whole different approach to that lab (or whatever has replaced it now) when the course opens, especially having my knowledge of data structures and things now. I feel more prepared than ever to tackle these labs now, mostly because I don't intend to waste time with things and procrastinate before getting them done, so I will have plenty of time to research, get help, etc. I have thought about this course too many semesters to let it get away now. My self-esteem needs to take and pass this course (honestly, I need an A...I have only gotten one non-A at CPCC and it kills me).

Anyway... whatever I do this semester has to be better than this:

//Written by Curtis M. Kularski
//CSC234 - 85
//Lab 02 - Banking Simulation


#include <stdlib.h>
#include <iostream>
#include <iomanip>

using namespace std;

class Teller
{
private: 
    int timer;
    bool isBusy;
    
public: 
    void setTimer(int K)
    {
     timer = 1+rand()%K;
    }

    void decrementTimer()
    {
     timer--;
    }

    int getTimer()
    {
    return timer;
    }
    
    void setBusy(bool busy)
    {
         isBusy = busy;
    }
};



class Customer
{
private:
    int wait;
    int timeInQueue=0;
    bool inQueue;

public: 
    void incrementWait()
    {
      wait++;
      if (inQueue == true)
      {
        timeInQueue++;
      }
    }
    void setTimer()
    {
     wait = 0; 
    }
};


int intializeTellers(int, Teller []);
void createCustomers(int, int, Customer [])
int addCustomers(int);



int main()
{

int i, M, N, K, totalCustomers;
cout << "How many iterations would you like to test? ";
cin >> i;

cout << "\nMaximum customers added per iteration? "; 
cin >> M;


cout << "\nHow many tellers will be working? ";
cin >> N;

cout << "\nWhat is the maximum time a teller spends on a transaction? ";
cin >> K;

cout << "\n\n";

int numCustomers = 0, newCustomers=0, numToRemove = 0, freeTellers;
Teller tellers[N];
initializeTellers(N, tellers);


Customer customers[20];
while (i >=1)
    {
      //Remove Customers who are done
      //Customers enter bank
            newCustomers = addCustomers(M);
            createCustomers(newCustomers, numCustomers, customers);
      //Free tellers are assigned customers, customers removed from queue and tellers isBusy=true, timers set
      //
      

      assignCustomersToTellers(tellers, customers);

   //display 
   
      i--;
      system("pause");
    }

return 0; 
}

 void initializeTellers(int N, tellers [])
 {
  while (N >= 1)
        {
          N--;
          tellers[N].setBusy(false);      
        }
 }


 void createCustomers(int newCustomers, int numCustomers, Customer customers[])
 {
      int j = 0;
      numCustomers--; 
      while (j <= newCustomers)
      {
            if (numCustomers + j + 1 < 20)
            {
             customers[numCustomers + (j+1)].setTimer();
             j++;
            }
            else {cout << "Array Full!"; break;}
      }
  }


int addCustomers(int maxNew)
{
int numToAdd = 1+rand()%maxNew;
return numToAdd;
}

Leave a comment

About this Entry

This page contains a single entry by Curtis published on July 29, 2008 11:19 PM.

Inconsistent Data was the previous entry in this blog.

Bisqueing Again is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.23-en