Linked Lists in Classes trouble

Hello! I'm pretty new at coding and am having some troubles understanding linked lists and how they work in classes. My code is going to have a bunch of errors, but hopefully one of you guys can help me understand what I'm doing wrong. Here is my goal so far for this assignment:

The end goal is to create a simulator that will aid in the study of tracking robots deployed to mine soil. The deployed robots will be of two distinct classes: miners and scouts.

All robots will be transported to Mars via a "mother ship" called Argus. Argus contains a control center from which all robots (or Argonauts) will be dispatched to the planet surface.Argus contains two two distinct holding areas for robots: one for miners and one for scouts.

The task is to simulate the movement of robots to and from the Argus, and keep track of the location and status of all robots. Your simulation will begin by reading a robot manifest from a file specified by the user. Each line of the manifest file contains information pertaining to a single robot. The info is presented as so:

RobotNumber RobotType RobotManufacturer

where RobotNumber is a unique number greater than zero and less than 2,000,000,000 that is assigned to each robot, RobotType is one of 'M' for miner or 'S' for scout, and RobotManufacturer is a string of no more than 64 characters identifying the manufacturer of a given robot.

Once your simulation has read all robots from the manifest file, it should begin interactively accepting command from the user.


Here is what I have for the code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>

using namespace std;
ifstream infile;

class LinkList
{

public:
    LinkList();
    LinkList(int, char, string);
    
//    Add(int RN, char RT, string Rn);
//    Remove(int RN);
private:
    struct node
    {
        int RoNum;
        char RoType;
        string RoMan;
        node *next;
    };
};

LinkList::LinkList(){
    int q = infile;
    int RN;
    char RT;
    string RM;
    
    while (q != NULL) //Link list process. Most confused here.
    {
        infile >> RN >> RT >> RM;
        Start.LinkList(int RN, char RT, string RM); //Placing info from the file into class variables
        q=q->next;
    }
}

LinkList::LinkList(int RN, char RT, string RM){
    RoNum = RN; //Not sure why the private variables don't carry through
    RoType = RT;
    RoMan = RM;
}

int main(int argc, char** argv) {
    LinkList Start;
    infile.open("Robot.txt"); //Open external file
    
    Start.LinkList(); //Call LinkList class function

    return 0;
}


At the moment I'm trying to input all the information from the file into the program. Thanks for the help!
.
@line 53 you cant call the constructor like that, it was automatically called for you at line50

now you know that, it looks like line51 needs to come before line 50 .

1
2
3
4
    infile.open("Robot.txt"); //Open external file
    LinkList Start;

    return 0;


also @line38 you are trying to access Start, which is a local variable in main().

instead of commenting the code for us, try commenting it for yourself, describe the process you are trying to achieve and then write the code to do that.
Last edited on
Topic archived. No new replies allowed.