well I am back with the code agin. I am trying to print the whole queueu. I can cout the front and rear but I can get the PrintQ() to work.
phillipeharris 0 Newbie Poster
//***************************************************************
// TITLE: Contributor
// FILE: Contributor.cpp
// PREPARED FOR: CS230 Section <section number>
// PROGRAMMER(S): < Phillip Harris>
// DEVELOPMENT DATE: < 07/09/08>
// COMPILER USED: <MS visual studio 2005>
// TARGET PLATFORM: < WIN XP >
//================================================================
// PROJECT FILES
// contributor.h, contributor.cpp, Lab1.cpp
//================================================================
// REVISION HISTORY
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// <07/08/08 Phil Harris Original >
//================================================================
#include <iostream>
#include <string>
#include <iomanip>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;
///c-tor implementation
int num =1;
Contributor::Contributor()
{
Name = "";
Contribution = 0.0f;
Sex = None;
IDKey = 0;
}
//copy C-tor
Contributor::Contributor(string InContrib, double InContribution, Gender InSex, int InIDKey)
{
Name= InContrib;
Contribution= InContribution;
Sex = InSex;
IDKey= InIDKey;
}
Contributor::Contributor(const Contributor &CCContrib)
{
Name = CCContrib.Name;
Contribution= CCContrib.Contribution;
Sex = CCContrib.Sex;
IDKey = CCContrib.IDKey;
}
ostream &operator <<(ostream & Out,Contributor &InContrib)
{
//Out<<endl<<num<<"\tName of the Contributor? " <<endl;
Out<<"\tName: " <<InContrib.Name <<endl;
Out<<"\tID Number: " <<InContrib.IDKey<<endl;
//Out<<endl<<num<<endl;
Out<<"\tContribution: "<<InContrib.Contribution<<endl;
Out<<"\tGender: ";
switch (InContrib.Sex)
{
case Male: Out<<" Male ";break;
case Female: Out<<" Female ";break;
//default: Out<<"NONE";break;
}
num++;
Out<<endl<<endl;
return Out;
}
/*istream &operator >> (istream &In,Contributor &InContrib)
{
int SelSex = 0;//selection of gender
In.clear();
In.ignore(In.rdbuf()->in_avail(), '\n');
cout<<"\tEnter Contirbutors Name: ";
getline(In,InContrib.Name);
cout<<"\tEnter the amount of "<<InContrib.Name <<"'s contribution ";
In>>InContrib.Contribution;
cout<<"\tNow Enter an ID# for "<<InContrib.Name<<" ";
In>>InContrib.IDKey;
cout<<"\twhat is "<<InContrib.Name<<"'s Gender? "<<endl;
cout<<"\t1. Male. \n\t2. Female \n\t3. None\n\n";
In >> SelSex;
switch(SelSex)
{
case 1: SelSex = Male; break;
case 2: SelSex = Female; break;
case 3: SelSex = None; break;
}
return In;
}
*/
Contributor &Contributor::operator = (const Contributor & RtSide)
{
if(this != &RtSide)
{
Name = RtSide.Name;/////
Contribution = RtSide.Contribution;
Sex = RtSide.Sex;
IDKey = RtSide.IDKey;/////
}
return *this;
}
bool Contributor::operator <(const Contributor & RtSide)
{return (Contribution <RtSide.Contribution);}
bool Contributor::operator >(const Contributor & RtSide)
{return (Contribution <RtSide.Contribution);}
bool Contributor::operator ==(const Contributor & RtSide)
{return ((Name == RtSide.Name)&&(Contribution==RtSide.Contribution)&&(Sex== RtSide.Sex));
}
bool Contributor::operator !=(const Contributor & RtSide)
{return((Name != RtSide.Name)||(Contribution!=RtSide.Contribution)||(Sex != RtSide.Sex));
}
// TITLE: Contributor
// FILENAME: Contributor.h
// PREPARED FOR: CS230 Section <section number>
// PROGRAMMER(S): < Phillip Harris>
// DEVELOPMENT DATE: < 07/09/08>
// COMPILER USED: <MS visual studio 2005>
// TARGET PLATFORM: < WIN XP >
//================================================================
// PROJECT FILES
// contributor.h ,contributor.cpp, Lab1.cpp
//================================================================
// REVISION HISTORY
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// <07/08/08 Phil Harris Original >
//
//================================================================
// PROCESS THIS FILE ONLY ONCE PER PROJECT
#ifndef CONTRIBUTOR_H
#define CONTRIBUTOR_H
#include <iostream>
#include <string>
//#include "myQueue.h"
using namespace std;
//================================================================
//CONSTANT DEFINITIONS
enum Gender {Male=0, Female, None};
class Contributor
{
friend ostream &operator <<(ostream & Out,Contributor &InContrib);
friend istream &operator >>(istream & In, Contributor &InContrib);
public:
Contributor();
Contributor(string InContrib, double InContribution, Gender inSex, int InIDKey);
Contributor(const Contributor &CCContrib);
/////Overloaded Operators
Contributor &operator=(const Contributor & RtSide);
bool operator <(const Contributor & RtSide);
bool operator >(const Contributor & RtSide);
bool operator ==(const Contributor & RtSide);
bool operator!=(const Contributor & RtSide);
bool insertNode(Contributor i);
private:
string Name;
double Contribution;
Gender Sex;
int IDKey;
};
#endif
//***************************************************************
// TITLE: Contributor
// FILE: Contributor.cpp
// PREPARED FOR: CS230 Section <section number>
// PROGRAMMER(S): < Phillip Harris>
// DEVELOPMENT DATE: < 07/13/08>
// COMPILER USED: <MS visual studio 2005>
// TARGET PLATFORM: < WIN XP >
//================================================================
// PROJECT FILES
// contributor.h, contributor.cpp, Lab1.cpp
// myQueue.h, myQueue.cpp
//================================================================
// REVISION HISTORY
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// <07/08/08 Phil Harris Original >
//================================================================
#include <iostream>
#include <string>
#include <list>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;
int main()
{
myQueue ObjQue;// this makes the Queue
ObjQue.IsEmpty();
ObjQue.IsFull();
Contributor A("Phillip", 19.72, Male, 38);
Contributor B("Joanna", 19.69, Female, 39);
Contributor C("Hannah", 19.99, Female, 9);
Contributor D("Rachel", 20.01, Female, 7);
Contributor E("Raymond",19.48, Male, 59);
Contributor F("Dottie", 19.52, Female, 55);
Contributor G("Amanda", 19.68, Female, 40);
Contributor H("David", 19.71, Male, 37);
ObjQue.enQueue(A);
ObjQue.enQueue(C);
ObjQue.enQueue(D);
ObjQue.enQueue(E);
ObjQue.enQueue(F);
ObjQue.enQueue(G);
ObjQue.enQueue(H);
ObjQue.ShowFront();
cout<<ObjQue.enQueue(E);
ObjQue.ShowRear();
ObjQue.PrintQ();
return 0;
}
//***************************************************************
// TITLE: Contributor
// FILEInContrib: Contributor.cpp
// PREPARED FOR: CS230 Section <section number>
// PROGRAMMER(S): < Phillip Harris>
// DEVELOPMENT DATE: < 07/09/08>
// COMPILER USED: <MS visual studio 2005>
// TARGET PLATFORM: < WIN XP >
//================================================================
// PROJECT FILES
// contributor.h, contributor.cpp, Lab1.cpp
//================================================================
// REVISION HISTORY
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// <07/08/08 Phil Harris Original >
//================================================================
#include <iostream>
#include <string>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;
myQueue::myQueue()
{
front=0;
rear =0;
Index=0;
size= 0;
ArrayQ[10];
}
myQueue::myQueue(const myQueue &CCmyQueue)
{
for(int i=0;i < CCmyQueue.Index;i++)
{
ArrayQ[i]=CCmyQueue.ArrayQ[i];
front= CCmyQueue.front;
rear =CCmyQueue.rear;
Index=CCmyQueue.Index;
size =CCmyQueue.size;
}
}
myQueue &myQueue:: operator =(const myQueue & RHS)
{
if(this!= &RHS)
{
for (int i=0; i<RHS.Index;i++)
{
ArrayQ[i]= RHS.ArrayQ[i];
Index = RHS.Index;
rear= RHS.rear;
front= RHS.front;
size= RHS.size;
}
}
return *this;
}
myQueue::~myQueue()
{
cout<< "default D-Tor"<<endl;
}
bool myQueue::enQueue(Contributor InData)
{
if(IsFull())
{
cout<< " Queue is full"<<endl;
return false;
}else{
ArrayQ[rear]=InData;
step(rear);
Index++;
}
cout<<"Index ="<<Index<<endl;
return true;
}
bool myQueue::deQueue()
{
if(IsEmpty())
{
cout<<"the IsEmpty()";
}else{
step(front);
--Index;
}
return true;
}
bool myQueue::IsFull()
{
cout<< " the IsFull ()"<<endl;
if(Index==MAXSIZE)
{
return true;
}
return false;
}
bool myQueue::IsEmpty()
{
if(Index==0)
return true;
}
void myQueue::step(int &num)
{
if(num==(size-1))
{
num=0;
}else{
num++;
}
}
void myQueue::ShowFront()
{
cout<<ArrayQ[front]<<endl;
}
void myQueue::ShowRear()
{
cout<<ArrayQ[rear]<<endl;
}
void myQueue::PrintQ()
{
for (int i=0;i>MAXSIZE;++i)
{
cout<<ArrayQ[i];
++i;
}
}
#ifndef myQueue_H
#define myQueue_H
#include <iostream>
#include <string>
#include "Contributor.h"
using namespace std;
const int MAXSIZE=10;
class myQueue
{
public:
myQueue();
myQueue(Contributor InData);
myQueue(const myQueue &CCmyQueue);
myQueue &operator=(const myQueue & RHS);
~myQueue();
bool enQueue(Contributor InData);
bool deQueue();
bool IsFull();
bool IsEmpty();
void step(int &num);
void ShowFront();
void ShowRear();
void PrintQ();
private:
int front;
int rear;
int Index;
int size;
Contributor ArrayQ[MAXSIZE];
Contributor Data;
};
#endif
phillipeharris 0 Newbie Poster
I am soooooo stupid... I alked away to get a sandwich and took another look and found out that I should have said < instead of >
henpecked1 0 Posting Whiz in Training
Now mark your post as solved...lol.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.