-2
#include "Data.h"

#include "Heap.h"

#include "PQ.h"
#include <iostream>

using namespace std;

//**********************************************************

void enqRequest(int newTrackNum, int currP ,int serialNumber,bool 
forwardDir, itemClass &item(int &newTrackNum,int &serialNumber))

{

cout << "Do the EnqRequest function."<<endl;
cout <<endl<<endl;
cout <<"Enter a New Track Number"<<endl;
cin >> newTrackNum;

if (newTrackNum >= 0 && newTrackNum <= 9) {




 cout <<"EnqRequest   "<<newTrackNum<<endl;
 cout << endl << endl;
 cout <<"Current Position: .............."<<currP<<endl;
 cout <<"Current Direction: ............."<<endl;
 cout <<"Request was Enqueued in the: ..."<<endl;
 cout <<"Number of Request is: ......"<<endl;
 cout      <<"======================================================================    ======"<<endl;
    }
    else
        cout <<"Please Enter a number request between 0-9"<<endl;




}
//**********************************************************


int main(void) {


bool user = true;
bool fowardDir= true;
string commandUser;
int  trackNum, currentPosition,T;
T=0;

pqItemType forward;
pqItemType reverse;
itemClass item(int trackNum, int T);


currentPosition=0;
cout << "WELCOME TO THE DISK SCHEDULER"<<endl;
cout << "THE COMMANDS AVAILABLE TO YOU ARE \"EnqRequest\", \"ServeRequest\", \"PrintState\", AND \"Quit\"\n";
cin >> commandUser;
std::transform(commandUser.begin(), commandUser.end(), commandUser.begin(), ::toupper);

do{
    if ( commandUser == "ENQREQUEST" )
    {
        enqRequest(trackNum,currentPosition,T,fowardDir,&item);


        cout << "THANK YOU FOR USING THE DISK SCHEDULER"<<endl;
        cout << "THE COMMANDS AVAILABLE TO YOU ARE \"EnqRequest\", \"ServeRequest\", \"PrintState\", AND \"Quit\"\n";
        cin >> commandUser ;
        std::transform(commandUser.begin(), commandUser.end(), commandUser.begin(), ::toupper);
    }
  else
    {
        cout << "Please, enter a command" << endl;
        cin >> commandUser;
        std::transform(commandUser.begin(), commandUser.end(), commandUser.begin(), ::toupper);
    }

}while (user);


return 0;
}

I have an object item with arguments (int trackNum, int T); I am trying to pass a reference to this object into enqRequest function and other functions not made yet. When I pass the objects reference, do I also have to specifically pass arguments used by the object itself? For example

void enqRequest(itemClass &item(int &newTrackNum,int &serialNumber))
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
crod
  • 235
  • 3
  • 5
  • 12
  • C does not have the ability to pass "by reference". Instead, pass the address of the variable in question and have the function receive a pointer to the type. – chux - Reinstate Monica Nov 15 '15 at 05:18
  • @chux There's no way this code can be C (despite the tag, which has just been removed). Look at all the `cin`s and `cout`s. This is C++, and pass-by-reference is possible. – Fabio says Reinstate Monica Nov 15 '15 at 05:22
  • Yes my mistake I meant C++ – crod Nov 15 '15 at 05:25
  • what do u mean by object item with arguments? class (and their objects) have properties. – Nandu Nov 15 '15 at 05:40
  • @crod When you say "I have an object item with arguments (int trackNum, int T);" are you talking about the line `itemClass item(int trackNum, int T);`? If so... `item` is not an object, it's a function, which takes 2 `int`s as arguments and returns an `itemClass`. And you are declaring that function inside `main()`, which is legal but strange, and [probably not what you mean](http://stackoverflow.com/questions/1034606/is-there-any-use-for-local-function-declarations). – Fabio says Reinstate Monica Nov 15 '15 at 05:45
  • @Fabio Turati I simple assumed OP wanted to do a similar thing in C. – chux - Reinstate Monica Nov 15 '15 at 05:54

1 Answers1

1

the following object construction is wrong: itemClass item(int trackNum, int T);

it should be:

itemClass item(trackNum, T);

This assumes that you have a constructor that assigns trackNum, T parameters to the class members of itemClass.

if you want to pass reference to this object, the calling signature would be:

enqRequest(trackNum,currentPosition,T,fowardDir,item);

The function enqRequest needs to be:

void enqRequest(int newTrackNum, int currP ,int serialNumber,bool 
forwardDir, itemClass &item)
{
cout << "Do the EnqRequest function."<<endl;
cout <<endl<<endl;
cout <<"Enter a New Track Number"<<endl;
cin >> newTrackNum;

if (newTrackNum >= 0 && newTrackNum <= 9) {
 cout <<"EnqRequest   "<<newTrackNum<<endl;
 cout << endl << endl;
 cout <<"Current Position: .............."<<currP<<endl;
 cout <<"Current Direction: ............."<<endl;
 cout <<"Request was Enqueued in the: ..."<<endl;
 cout <<"Number of Request is: ......"<<endl;
 cout      <<"======================================================================    ======"<<endl;
    }
    else
        cout <<"Please Enter a number request between 0-9"<<endl;




}
Nandu
  • 808
  • 7
  • 10