compshooter 17 Newbie Poster

I think what he's saying is there are two levels of interviews, HR and Technical. You have to get past the first to get to the second.

You can also argue there are three levels, automated resume scanner, HR Generalist then technical. If your resume has the right buzzwords you get past the scanner and onto the HR generalist.

They (HR) know buzzwords and industry words too, they just don't know what they mean. So you can BS your way through them. Then when you get to the technical interview it could come crashing down if you played up the buzziness on your first two interviews (scanner and HR). The technical interview can blow that out of the water.

So I think you need to have a good balance of including the right amount of buzziness in rounds one and two. But you have to have a ground to stand on those words in round three. It's a complicated balance that ultimately comes down to round three.

compshooter 17 Newbie Poster

I think rproffitt is ChatGPT is disguise.

rproffitt commented: I like the cut of your jib. +17
compshooter 17 Newbie Poster

It worked! Thanks so much:!:

compshooter 17 Newbie Poster

I am just trying to print out my array of binary values from 0 to 15. The output I get is wrong, very very wrong.

Can someone take a look at my code and enlighten me?

#include <iostream>
#include <conio.h>
using namespace std;
int binA[16][4] = {
  (0,0,0,0),(0,0,0,1),(0,0,1,0),(0,0,1,1),
  (0,1,0,0),(0,1,0,1),(0,1,1,0),(0,1,1,1),
  (1,0,0,0),(1,0,0,1),(1,0,1,0),(1,0,1,1),
  (1,1,0,0),(1,1,0,1),(1,1,1,0),(1,1,1,1)}; 
int main()
{
  cout<<"This is the bin array:"<<endl;
  for (int r=0; r<16; r++)
  {
      for (int v=0; v<4; v++)
      {
        int t=v%4;
        cout<<binA[r][v];
        if (v==3)
          cout<<" ";
      }
  } 
getch();
return 0;
}

The result I get is...

0101 0101 0101 0101 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

What's going on:?:

compshooter 17 Newbie Poster

Thank you so much! It worked!:mrgreen:

compshooter 17 Newbie Poster

I get the following error on the first line of my array...

" syntax error before `}' token "

My eyes are about to fall out of my skull. Can someone take a look for me, everything seems to be fine, but maybe I'm blind.


Here is the code in question...

int bin[26][5]={
                  {0,0,0,0,0},(0,0,0,0,1},{0,0,0,1,0},{0,0,0,1,1},{0,0,1,0,0},{0,0,1,0,1},
                  {0,0,1,1,0},{0,0,1,1,1},{0,1,0,0,0},{0,1,0,0,1},{0,1,0,1,0},{0,1,0,1,1},
                  {0,1,1,0,0},{0,1,1,0,1},{0,1,1,1,0},{0,1,1,1,1},{1,0,0,0,0},{1,0,0,0,1},
                  {1,0,0,1,0},{1,0,0,1,1},{1,0,1,0,0},{1,0,1,0,1},{1,0,1,1,0},{1,0,1,1,1},
                  {1,1,0,0,0},{1,1,0,0,1}
                  };
compshooter 17 Newbie Poster

AWESOME!

cin.ignore(); after the first cin.get() worked! I was going crazy. Thanks a lot!

compshooter 17 Newbie Poster

Here is my full code if anyone feels inclined to try it. The code is supposed to accept input via a file, encrypt it and then output the results on the screen and in a file.

The input file contains a key and a message like this...
(2,1,0,3,4)
thisclassisboring;
...the first line is the key and the second is the message.

I can't seem to be able to allow the user to enter the "output" file name.

Here is the code...

#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
using namespace std;

int n=0, z=0;                   //declare variables to count the amount of input
int main () 
{
  char ifname[150];              //declare input file name array
  char ofname[150];              //declare output file name array
  char key[13];
  char c;
  char intxt[256];
  char tmptxt[5];                      
  ifstream is;                  //declare ifstream to is
  ofstream os;                  //declare ofstream to os
  
  cout<<endl<< "Enter the path of the input file: ";  //enter filename and path  cin<<ifname[0]<<endl;
  cin.get(ifname, 150);          //grab filename from user
  is.open(ifname);               //open file
  cout<<endl;
 
    
  cout<<endl<< "Enter the path of the output file: ";  //enter filename and path
  cin.get(ofname, 150);          //grab filename from user
  os.open(ofname);               //open file
  cout<<endl;
//
//*******************get key
//
  for (int j=0; j<13; j++)
    {
        c=is.get();  
        key[j]=c;
    }       
//  cout<<"This is the key:  ";
  for (int k=0; k<12; k++)
    cout<<key[k];
//    cout<<endl;
    is.clear();                   //clear flags in ifstream
    is.seekg (13, ios::beg);      //set pointer to second line of input file
//
//*********************find out how long the message is
//
    for (int j=0;
compshooter 17 Newbie Poster

Thanks, but it didn't work. Any other ideas?:sad:

compshooter 17 Newbie Poster

I am trying to grab an input file and outfile file from the user. I can grab the input file no problem, but Dev C++ just steps right over the following line...

cin.get(ofname, 150);          //grab filename from user

Here is some more of the code. Does anyone have any idea what I'm doing wrong?

#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
using namespace std;

int n=0, z=0;                   //declare variables to count the amount of input
int main () 
{
  char ifname[150];              //declare input file name array
  char ofname[150];              //declare output file name array
  char key[13];
  char c;
  char intxt[256];
  char tmptxt[5];                      
  ifstream is;                  //declare ifstream to is
  ofstream os;                  //declare ofstream to os
  
  cout<<endl<< "Enter the path of the input file: ";  //enter filename and path  cin<<ifname[0]<<endl;
  cin.get(ifname, 150);          //grab filename from user
  is.open(ifname);               //open file
  cout<<endl;
  
  cout<<endl<< "Enter the path of the output file: ";  //enter filename and path
  cin.get(ofname, 150);          //grab filename from user
  os.open(ofname);               //open file
  cout<<endl;
compshooter 17 Newbie Poster

OK, I've been banging my head against a wall for a few hours. And I need some sleep. Can someone please show my how to accept input and keep count of it so I can send WriteBytes2() the address of the buffer and the number of bytes entered?

Here is a snipet of what I have...

quit = false;
while (buffer!=CR)
{
	cin>>buffer;count++;
	WriteBytes2(&buffer, count); //write to other terminal
	if (buffer=='?') 
	{					//check for quit command
		quit=true;
		return 0;
	}
}

but the count isn't right. My output is garbage. The sad thing is about 4 hours ago I had this thing working but I don't know what I changed that messed the count up (besides deleting it in the first place).

Background: I am writing a program that will accept user input and send it over the serial port.

Thank you :eek:

compshooter 17 Newbie Poster

That would probably be the easiest way. Thanks for the quick reply!

compshooter 17 Newbie Poster

I have three doubly linked list queues and I need to sort them based on a variable that each object has namely its job length. I am attempting to code for a shortest job first processing program. I already have most of the program complete but now I need to sort the queues so the shortest jobs are first in line.

What would be the best/easiest/least amount of code way to sort these queues?

thank you!

compshooter 17 Newbie Poster

I have a couple of questions about the main function. Do you need to put the ; after the last }? Do you need to put a return statement before the last }? If so, what number do you put in the (), i.e. return (0), return (1), etc. What does the number mean?

Here are a couple of simple programs that all compile and run without errors in Dev C++ 4.9.9.0. Which one is the correct or the proper way to create a main function? And why?

NO RETURN, NO ;

#include<iostream>

using namespace std;

int main()
{
	cout<<"test"<<endl;
	system("pause");
}

NO RETURN

#include<iostream>

using namespace std;

int main()
{
	cout<<"test"<<endl;
	system("pause");
};

NO ;

#include<iostream>

using namespace std;

int main()
{
	cout<<"test"<<endl;
	system("pause");
	return(0);
}

RETURN AND ;

#include<iostream>

using namespace std;

int main()
{
	cout<<"test"<<endl;
	system("pause");
	return(0);
};

Thank You! :confused:

compshooter 17 Newbie Poster

Hey, I am pretty new to this site and have learned a lot of C++ with the help of these kind folks. I looked at your problem and attempted to solve it myself. Here is what I got. It seems to work for me.

BTW, working on your problem helped my understand of reference variables! It was fun!

#include <iostream>

using namespace std;

void getDrawers(int *numDrawers);
void getWood(int *woodFactor);
double getTotal(int numDrawers,int woodfactor,double *total);
void PrintPrice(double total);     

int main()
{
    int numDrawers=0, woodFactor=0;
    double total=0;
    getDrawers(&numDrawers);
    getWood(&woodFactor);
    getTotal(numDrawers,woodFactor,&total);
    PrintPrice(total);     
    cin.get();
    return (0);
};

void getDrawers(int *numDrawers) 
{
    int num;
    cout<<"Enter the number of drawers you would like."<<endl;
    cin>>num;
    *numDrawers = num;
    
}

void getWood(int *woodFactor) 
{
    char x;
    int i=0;
    char woods[3] = {'M', 'O', 'P'};
    int cost[3] = { 180, 140, 100};

    cout<<"Please choose the wood you would like for your desk;"<<endl;
    cout<<"M for Mahogany, O for Oak, P for Pine."<<endl;
    cin >> x;

    switch (x)
    {
        case 'M':
            *woodFactor = 180;
            break;
        case 'm':
            *woodFactor = 180;
            break;
        case 'O':
            *woodFactor = 140;
            break;
        case 'o':
            *woodFactor = 140;
            break;
        case 'P':
            *woodFactor = 100;
            break;
        case 'p':
            *woodFactor = 100;
            break;
        default:
            *woodFactor = 1000;
            break;
        }
}


double getTotal(int numDrawers, int woodFactor,double *total) 
{
    *total = numDrawers + woodFactor;
}

void PrintPrice(double total)
{
    cout << "The price of this desk is $"<<total<<endl;
}

I hope that helps you.

compshooter 17 Newbie Poster

Never mind, I figured it out!!! :cheesy:

Here is the code I had to change...

void Queue::addRearNode(NodeType newJob)
{
    if (isFull())
        throw FullQueue();
    else 
    {
        NodeType* newNode;
        newNode = new NodeType;
        newNode->name = newJob.name;
        newNode->aTime = newJob.aTime;
        newNode->length = newJob.length;
        newNode->switches = newJob.switches;
        newNode->fTime = newJob.fTime;
        newNode->sTime = newJob.sTime;
        newNode->urgent = newJob.urgent;
        newNode->type = newJob.type;
        
        newNode->next = NULL;
        if (rear == NULL)
                front = newNode;
        else
                rear->next = newNode;
        rear = newNode;
        items++;
    }
}    

void Queue::addFrontNode(NodeType newJob)
{
    if (isFull())
        throw FullQueue();
    else
    {
        NodeType* newNode;
        newNode = new NodeType;
        newNode->name = newJob.name;
        newNode->aTime = newJob.aTime;
        newNode->length = newJob.length;
        newNode->switches = newJob.switches;
        newNode->fTime = newJob.fTime;
        newNode->sTime = newJob.sTime;
        newNode->urgent = newJob.urgent;
        newNode->type = newJob.type;
        newNode->next = NULL;
        if (front ==NULL)
                rear = newNode;
        else
                front->next = newNode;
        front = newNode;
        items++;
    }
}

I was trying to just assign the name of the old object to the new one. But I had to actually assign each member in the old object to each member in the new object. Once I did that, everything worked out!

And besides figuring it out, it makes sense too!!! :p

compshooter 17 Newbie Poster

Easy,
1. You have 'front' defined as pointer and you're using the '.', think of '->'
2. You are accessing name, but name is defined in class 'info'

i could fix it but it looks like you'll get it.

INTEL

ok, I changed the output lines to this...

cout<<"MM ITEMS:  "<<mm.items<<endl;
     cout<<"FP ITEMS:  "<<fp.items<<endl;
     cout<<"TXT ITEMS:  "<<txt.items<<endl;
     cout<<"CTIME:  "<<cTime<<endl;
     cout<<"Front Name: "<<mm.front->name<<endl;

Now it prints out the number of items in each queue but the last line only prints out a bunch of nonsense and I get an access violation error.

It sounds like my pointer is pointing somewhere it shouldn't be. What is going on?

I also changed around the queue class and the nodetype class to this...

class NodeType
{
public:
NodeType* next;
NodeType* back;
int	switches, fTime, sTime;
int length, aTime;
string name;
string type;
string urgent;
string getName()
{
    return name;
}    

NodeType()
{
	switches=0;
	fTime=0;
	sTime=0;
};
~NodeType()
{
};

class Queue
{  
public:
    Queue();
    ~Queue();
    
    void makeEmpty();
    void addFrontNode(NodeType newJob);
    void addRearNode(NodeType newJob);
    void delNode(NodeType &delJob);
    bool isEmpty() const;
    bool isFull() const;
    int getItems();
    int items;
    
    NodeType* front;
    NodeType* rear;
};

Also, please look at my addNode fuction. Maybe its not actually putting the items into the queue?

void Queue::addRearNode(NodeType newJob)
{
    if (isFull())
        throw FullQueue();
    else 
    {
        NodeType* newNode;
        newNode = new NodeType;
        newNode = &newJob;
        newNode->next = NULL;
        if (rear == NULL)
                front = newNode;
        else
                rear->next = newNode;
        rear = newNode;
        items++;
    }
}
compshooter 17 Newbie Poster

Ok, I have three queueus, MM, FP & TXT. Each of them contain objects which have variables associated with them. How do I access any of the variables that the front of my Queue points to?

For example, I am trying to print out the name of the item that is in the begginning of my MM queue.

I want to type something like...

cout<<mm.front.name<<;

but that doesn't work. I tried many variations on that but to no avail. Below is my pertinent code. Any help is greatly appreciated. Thanks!

class NodeType
{
public:
job info;
NodeType* next;
NodeType* back;
};



class Queue
{
public:
Queue();
~Queue();


void makeEmpty();
void addFrontNode(job newJob);
void addRearNode(job newJob);
void delNode(job &delJob);
bool isEmpty() const;
bool isFull() const;
int getItems();
int items;


NodeType* front;
NodeType* rear;
};



class job
{
public:
int switches, fTime, sTime;
int length, aTime;
string name;
string type;
string urgent;
string getName()
{
return name;
}


job()
{
switches=0;
fTime=0;
sTime=0;
};
~job()
{
};
compshooter 17 Newbie Poster

From your earlier posting of the class, it looks like a linked list was at least implied.

job* next;
job* back;

Yes, each line of the input file is a job which we have to process and then place into one of three doubly linked lists (as a queue) according to the job's type (either mm, fp or txt),

We are trying to simulate a priority alogrithm of an operating system. And as such as we read each job (line) we process it by decreasing its job length and place it into the appropriate queue. Then we increase the system time and process the next job and so on.

But at some point the system time will be greater than the arrival time of the new job so the job won't be processed ( don't decrease it's job length), it will just be put into the queue.

Then just to make it fun, some jobs have a priority to them. It's the last bit of info on the line, either Y or N. If it is Y, then the job has to bump up to the front of the queue.

Oh boy I love this stuff!

compshooter 17 Newbie Poster

Thank you for all your help so far. I took what you gave me and modified it so I can place each line into a new object.

I feel as though my code can be improved upon since I am declaring a known amount of objects (since I can see the contents of the input file). It seems like cheating to me. Can anyone think of a way to somehow loop the input into new objects until there are no more lines to read?

I tried...

int i=0;
getline(iFile, line);     
      myjob[i].read(line);
      cout<<"myjob "<<i<<endl;
      myjob[i].show();

But the compiler doesn't like myjob[i]. It says it is undeclared. I am not allowed to use arrays by the way and it probably thinks it is an array. I am using objects declared (or trying to be declared as) myjob0, myjob1, myjob2, etc.

Anyhow, I coded for the first 5 objects and lines to be read from the file. Before I make a big ugly mess of something that is probably much simpler to do, can someone give me a clue in the right direction?

Below is what I have so far.

Thanks a bunch I am learning a lot of C++ today!!!

:cool:

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;

class job
{
   string  name;
   int     length, time;
   string  type;
   char    urgent;
public:

   bool read(string &line)
   {
      istringstream iss(line);
      return iss >> name >> length >> time >> type >> urgent;
   }
   void show()
   {
      cout <<
compshooter 17 Newbie Poster

Ok, I think I'm screwing things up big time trying to use templates, apparently incorrectly. Now I can create my job objects that I need but I am still having problems reading from the file. Help?

So here is another version without templates...

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

class job 
{
public: 
    job()
    {
        int switches=0;
        int fTime=0;
        int urgent=0;
    }    
    job::~job()
    {
    } 

    job* next;
    job* back;

    void setName(string name);
    string getName();
    void setLength(int length);
    void decLength(int length);
    int getLength();
    void setAtime (int time);
    int getAtime();
    void setStime (int sTime);
    int getStime();
    void setFtime (int fTime);
    int getFtime();
    void incSwtch (int switches);
    int getSwitch();
    void setType (string type);
    string getType();
    void setBool (bool urgent);
    bool getBool();
private:
    string _name;
    int _length;
    int _aTime;
    int _sTime;
    int _fTime;
    int _switches;
    string _type;
    bool _urgent;
};

int main()
{

    job buff;
    job mm;
    job txt;
    job fp;

    ifstream iFile("d:/input1.txt");

      if (! iFile)
    {
        cout << "Error opening input file" << endl;
        return -1;
    }
    cout << "File opened" << endl;

    while(!iFile.eof())
   {
        getline(iFile, buff.setName, ' ');
        getline(iFile, buff.setLength, ' ');
        getline(iFile, buff.setAtime, ' ');
        getline(iFile, buff.setType, ' ');
        getline(iFile, buff.setBool, ' ');
    }
    iFile.close();
}

void job::setName(string name)
    {
        _name=name;
    } 
string job::getName()
    {
        return _name;
    }
void job::setLength(int length)
    {
        _length=length;
    }
void job::decLength(int length)
    {
        _length=_length-50;
    }
int job::getLength()
    {
        return _length;
    }
void job::setAtime (int aTime)
    {
        _aTime=aTime;
    }
int job::getAtime()
    {
        return _aTime;
    }    
void job::setStime (int sTime)
    {
        _sTime=sTime;
    }    
int
compshooter 17 Newbie Poster

[QUOTE=Dave Sinkula]Show us the code from your initial attempt and describe the shortcomings.[/QUOTE]

OK, but please don't laugh. I am not good at coding so I'm sure you'll find plenty of mistakes. BTW, I am also having a problem creating objects of my job class using templates (that's why it's commented out).

My assignment is to put these jobs (each line of the input file) into a queue based on its type; mm, fp or txt. So I will need 3 queues.

So my idea was to read each job or line from the file, place it in a job object called "buff", determine its type, place it in its appropriate job object (mm, fp or txt) and read the next line into the "buff" object until all the lines have been read and sorted into their approriate objects.

Thanks for looking!

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
template <class ItemType>
class job 
{
public: 
    job()
    {
        ItemType switches=0;
        ItemType fTime=0;
        ItemType urgent=0;
    }    
    job::~job()
    {
    } 

    job<ItemType>* next;
    job<ItemType>* back;

    void setName(ItemType name);
    ItemType getName();
    void setLength(ItemType length);
    void decLength(ItemType length);
    ItemType getLength();
    void setAtime (ItemType time);
    ItemType getAtime();
    void setStime (ItemType sTime);
    ItemType getStime();
    void setFtime (ItemType fTime);
    ItemType getFtime();
    void incSwtch (ItemType switches);
    ItemType getSwitch();
    void setType (ItemType type);
    ItemType getType();
    void setBool (ItemType urgent);
    ItemType getBool();
private:
    ItemType _name;
    ItemType _length;
    ItemType _aTime;
    ItemType _sTime;
    ItemType _fTime;
    ItemType _switches;
    ItemType _type;
    ItemType _urgent;
};

int main()
{
    /*
    job<ItemType> buff;
    job<ItemType> mm; …
compshooter 17 Newbie Poster

Hello evreryone,

I want to start by saying I did use the search function and I did read the fstream tutorial. But I didn't see the answer I need.

I have been given a text file for which I need to read input from. Here is a partial listing of the file...

BAK 90001 200 TXT N
CRSC 90010 150 TXT N
MARY 90011 140 FP N
CARL240 90050 300 FP N
LOW236 90052 150 FP N

The file contains four columns which need to be put into different members of the class. For example, how can I read the first line and put "BAK" into member0, "90001" into member1, "200" into member2, "TXT" into member3 and "N" into member four?

Also, after reading the first line, I need to stop reading the file to perform some functions then continue reading the file on the next line. This repeats until all the lines are read.

Any help is greatly appreciated! :confused: