I am trying to make a first fit memory management code but everytime I try to run it I keep getting incomplete results in the output and these errors
error:expected primary-expression before ‘,’ token
I don't know what to put in the code to resolve this error
#include"stdafx.h"
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<memory.h>
#include <cstdlib>
using namespace std;
struct allocList
{
char* startAlloc;
char* endAlloc;
int fk_pid;
allocList *nxt;
};
struct procList
{
int pid;
int jobstatus;
char *startProc;
char *endProc;
procList *nxt;
};
bool initProc(procList*&, int*, int);
bool initAlloc(allocList*&, int*, int);
int doFirstFit(procList*, allocList*);
int cmptFragmentation(procList*, allocList*);
int search(procList*, int);
bool reset(procList*, allocList*);
int main()
{
int arrMemory[] = { 100, 500, 200, 300, 600 };
int arrJobs[] = { 212, 17, 112, 426, 500 };
allocList *ptrAllocStart = NULL;
procList *ptrProcStart = NULL;
initAlloc(ptrAllocStart, arrMemory, (sizeof(arrMemory) / sizeof(int)));
initProc(ptrProcStart, arrJobs, (sizeof(arrJobs) / sizeof(int)));
cout << "Memory Block: " << endl << "Block\tSpace" << endl;
for (int i = 0; i < sizeof(arrMemory) / sizeof(int); i++)
{
cout << i + 1 << "\t" << arrMemory[i] << endl;
}
cout << "\nJobs:" << endl << "Job\tSize" << endl;
for (int i = 0; i < sizeof(arrJobs) / sizeof(int); i++)
{
cout << i + 1 << "\t" << arrJobs[i] << endl;
}
int jobLoaded = 0;
int fragmentation = 0;
jobLoaded = doFirstFit(ptrProcStart, ptrAllocStart);
fragmentation = cmptFragmentation(ptrProcStart, ptrAllocStart);
allocList* memtrav = ptrAllocStart;
getch();
return 0;
}
bool initProc(procList*& ptrProcStart, int* ptrArrProc, int length){
int i;
procList *ptrProc=ptrProcStart;
for(i=0; i<length; i++){
if(ptrProc != NULL){
ptrProc->nxt=new procList;
ptrProc = ptrProc->nxt; ptrProc->startProc=(char*)malloc(*(ptrArrProc+i));
ptrProc->endProc=ptrProc->startProc + *(ptrArrProc+i);
memset(ptrProc->startProc,'a'+i,*(ptrArrProc+i));
ptrProc->jobstatus=0;
ptrProc->pid=i;
ptrProc->nxt=NULL;
}
else
{
ptrProc=new procList;
ptrProc->startProc=(char*)malloc(*(ptrArrProc+i));
ptrProc->endProc=ptrProc->startProc + *(ptrArrProc+i);
memset(ptrProc->startProc, 'a'+i, *(ptrArrProc+i));
ptrProc->jobstatus=0;
ptrProc->pid=i;
ptrProc->nxt=NULL;
ptrProcStart = ptrProc;}}
return true; }
bool initAlloc(allocList*& ptrAllocstart, int* ptrArrAlloc, int length)
{
//cout << "loading function initAlloc"<< "\t" << length << endl;
int i;
allocList* ptrAlloc = ptrAllocstart;
for (i = 0; i < length; i++)
{
//cout << "running loop 1st"<< "\t" << i << endl;
if (ptrAlloc != NULL)
{
ptrAlloc -> nxt = new allocList;
ptrAlloc = ptrAlloc->nxt;
//cout << "after new ptrAlloc" << endl;
ptrAlloc->startAlloc=(char*)malloc(*(ptrArrAlloc+i));
ptrAlloc->endAlloc=ptrAlloc->startAlloc + *(ptrArrAlloc+i);
memset(ptrAlloc->startAlloc,'a'+i,*(ptrArrAlloc+i));
ptrAlloc->nxt=NULL;
}
else
{ //cout << "inside else"<< "\t" << i << endl;
ptrAlloc= new allocList;
ptrAlloc->startAlloc-(char*)malloc(*(ptrArrAlloc+i));
ptrAlloc->endAlloc-ptrAlloc->startAlloc + *(ptrArrAlloc+i);
memset(ptrAlloc->startAlloc, 'a'+i, *(ptrArrAlloc+i));
ptrAlloc->nxt=NULL;
ptrAllocstart=ptrAlloc;
}
}
return true;
}
int doFirstFit(procList*, allocList*){
//cout lang ng UI
cout << "\n\nFirst Fit:\nMemory Block\tSize\tJob\tInternal " << " Fragmentation\n" << endl;
//declaration ng variable
int i = 0;
allocList* memory;
//mag do while sa memory n walang laman?
while (memory != NULL)
i++;
cout << "\t" << i << "\t" << memory->endAlloc - memory->startAlloc << "\t"
<< memory->fk_pid << "\t"
//<< memory->endAlloc - memory->startAlloc - search(procList,memory->fk_pid - 1)
<< endl;
memory = memory->nxt;
return 0;
}
int search(procList* job, int id)
{
int size = 0;
while (job != NULL)
{
if (job->pid == id)
{
size =atoi(job->endProc) - atoi(job->startProc);
break;
}
job = job->nxt;
}
return size;
}
int cmptFragmentation(procList * jobs, allocList * mem)
{
allocList* memtrav, * temp;
procList* jobtrav;
jobtrav = jobs;
memtrav = mem;
int freespace = 0, memsize, jobsize;
int i = 0;
while (memtrav->nxt != NULL)
{
if (memtrav->nxt->fk_pid == 0)
{
freespace += (memtrav->nxt->endAlloc - memtrav->nxt->startAlloc);
temp = memtrav->nxt;
memtrav->nxt = memtrav->nxt->nxt; delete temp;
}
memtrav = memtrav->nxt;
}
if (memtrav->fk_pid == 0)
{
freespace += (memtrav->endAlloc - memtrav->startAlloc);
memtrav = memtrav->nxt;
}
memtrav = mem;
while (memtrav != NULL)
{
jobsize = search(jobs, memtrav->fk_pid - 1);
memsize = memtrav->endAlloc - memtrav->startAlloc;
if (memtrav->fk_pid != 0)
{
memtrav->endAlloc = memtrav->startAlloc + jobsize;
}
freespace += (memsize - jobsize);
memtrav = memtrav->nxt;
}
memtrav = mem;
while (memtrav != NULL)
{
if (memtrav->nxt == NULL)
{
memtrav->nxt = new allocList;
memtrav = memtrav->nxt;
memtrav->startAlloc = (char*)malloc(freespace);
memtrav->endAlloc = memtrav->startAlloc + freespace;
memset(memtrav->startAlloc, 0, freespace);
memtrav->fk_pid = 0;
memtrav->nxt = NULL;
break;
}
memtrav = memtrav->nxt;
}
memtrav = mem;
cout << endl << endl << "Defragmentation\nMemory " << "Block\tSize\tJob\tFreeSpace\n";
while (memtrav != NULL)
{
i++;
cout << "\t" << i << "\t" << memtrav->endAlloc - memtrav->startAlloc << "\t" << memtrav->fk_pid
<< "\t" << memtrav->endAlloc - memtrav->startAlloc - search(jobs, memtrav->fk_pid - 1) << endl;
memtrav = memtrav->nxt;
}
while (jobtrav != NULL)
{
if (jobtrav->jobstatus == 0)
{
doFirstFit(jobs, mem);
cmptFragmentation(jobs, mem);
}
jobtrav = jobtrav->nxt;
}
return 0;
}
bool reset(procList* jobs, allocList* mem)
{
procList* tempj = jobs;
allocList* tempa = mem;
while (jobs->nxt != NULL)
{
jobs = jobs->nxt;
free(tempj);
tempj = jobs;
}
free(tempj);
while (mem->nxt != NULL)
{
mem = mem->nxt;
free(tempa);
tempa = mem;
}
free(tempa);
return true;
}
This is the part where I commented where the error has an issue with and I don't know what I'm doing wrong
<< memory->endAlloc - memory->startAlloc - search(procList,memory->fk_pid - 1)
Please help, thank you so much!
In this function call
search(procList,memory->fk_pid - 1)
there is used the type specifier procList instead of an expression.
Pay attention to that such a function definition where its parameters are not used
int doFirstFit(procList*, allocList*){
//cout lang ng UI
cout << "\n\nFirst Fit:\nMemory Block\tSize\tJob\tInternal " << " Fragmentation\n" << endl;
//declaration ng variable
int i = 0;
allocList* memory;
//..
does not make a sense.
Moreover there is used uninitialized pointer
allocList* memory;
in expressions like for example this
memory = memory->nxt;
that invokes undefined behavior.
The function is called with arguments as
doFirstFit(jobs, mem);
So you need use the passed arguments within the function instead of declaring local variables like this
allocList* memory;
In the analysis I've done the error is this
memory->endAlloc - memory->startAlloc - search(procList,memory->fk_pid - 1)
otherwise direct passing of proclist, you must declare its pointer variable just like you did for Alloclist memory; by same way you'll resolve this
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<memory.h>
#include <cstdlib>
using namespace std;
struct allocList
{
char* startAlloc;
char* endAlloc;
int fk_pid;
allocList *nxt;
};
struct procList
{
int pid;
int jobstatus;
char *startProc;
char *endProc;
procList *nxt;
};
bool initProc(procList*&, int*, int);
bool initAlloc(allocList*&, int*, int);
int doFirstFit(procList*, allocList*);
int cmptFragmentation(procList*, allocList*);
int search(procList*, int);
bool reset(procList*, allocList*);
int main()
{
int arrMemory[] = { 100, 500, 200, 300, 600 };
int arrJobs[] = { 212, 17, 112, 426, 500 };
allocList *ptrAllocStart = NULL;
procList *ptrProcStart = NULL;
initAlloc(ptrAllocStart, arrMemory, (sizeof(arrMemory) / sizeof(int)));
initProc(ptrProcStart, arrJobs, (sizeof(arrJobs) / sizeof(int)));
cout << "Memory Block: " << endl << "Block\tSpace" << endl;
for (int i = 0; i < sizeof(arrMemory) / sizeof(int); i++)
{
cout << i + 1 << "\t" << arrMemory[i] << endl;
}
cout << "\nJobs:" << endl << "Job\tSize" << endl;
for (int i = 0; i < sizeof(arrJobs) / sizeof(int); i++)
{
cout << i + 1 << "\t" << arrJobs[i] << endl;
}
int jobLoaded = 0;
int fragmentation = 0;
jobLoaded = doFirstFit(ptrProcStart, ptrAllocStart);
fragmentation = cmptFragmentation(ptrProcStart, ptrAllocStart);
allocList* memtrav = ptrAllocStart;
getch();
return 0;
}
bool initProc(procList*& ptrProcStart, int* ptrArrProc, int length){
int i;
procList *ptrProc=ptrProcStart;
for(i=0; i<length; i++){
if(ptrProc != NULL){
ptrProc->nxt=new procList;
ptrProc = ptrProc->nxt; ptrProc->startProc=(char*)malloc(*(ptrArrProc+i));
ptrProc->endProc=ptrProc->startProc + *(ptrArrProc+i);
memset(ptrProc->startProc,'a'+i,*(ptrArrProc+i));
ptrProc->jobstatus=0;
ptrProc->pid=i;
ptrProc->nxt=NULL;
}
else
{
ptrProc=new procList;
ptrProc->startProc=(char*)malloc(*(ptrArrProc+i));
ptrProc->endProc=ptrProc->startProc + *(ptrArrProc+i);
memset(ptrProc->startProc, 'a'+i, *(ptrArrProc+i));
ptrProc->jobstatus=0;
ptrProc->pid=i;
ptrProc->nxt=NULL;
ptrProcStart = ptrProc;}}
return true; }
bool initAlloc(allocList*& ptrAllocstart, int* ptrArrAlloc, int length)
{
//cout << "loading function initAlloc"<< "\t" << length << endl;
int i;
allocList* ptrAlloc = ptrAllocstart;
for (i = 0; i < length; i++)
{
//cout << "running loop 1st"<< "\t" << i << endl;
if (ptrAlloc != NULL)
{
ptrAlloc -> nxt = new allocList;
ptrAlloc = ptrAlloc->nxt;
//cout << "after new ptrAlloc" << endl;
ptrAlloc->startAlloc=(char*)malloc(*(ptrArrAlloc+i));
ptrAlloc->endAlloc=ptrAlloc->startAlloc + *(ptrArrAlloc+i);
memset(ptrAlloc->startAlloc,'a'+i,*(ptrArrAlloc+i));
ptrAlloc->nxt=NULL;
}
else
{ //cout << "inside else"<< "\t" << i << endl;
ptrAlloc= new allocList;
ptrAlloc->startAlloc-(char*)malloc(*(ptrArrAlloc+i));
ptrAlloc->endAlloc-ptrAlloc->startAlloc + *(ptrArrAlloc+i);
memset(ptrAlloc->startAlloc, 'a'+i, *(ptrArrAlloc+i));
ptrAlloc->nxt=NULL;
ptrAllocstart=ptrAlloc;
}
}
return true;
}
int doFirstFit(procList*, allocList*){
//cout lang ng UI
cout << "\n\nFirst Fit:\nMemory Block\tSize\tJob\tInternal " << " Fragmentation\n" << endl;
//declaration ng variable
int i = 0;
allocList* memory;
procList*ab;
//mag do while sa memory n walang laman?
while (memory != NULL)
i++;
int mem=memory->fk_pid - 1;
cout << "\t" << i << "\t" << memory->endAlloc - memory->startAlloc << "\t"<< memory->fk_pid << "\t"<< memory->endAlloc - memory->startAlloc - search(ab,mem)<< endl;
memory = memory->nxt;
return 0;
}
int search(procList* job, int id)
{
int size = 0;
while (job != NULL)
{
if (job->pid == id)
{
size =atoi(job->endProc) - atoi(job->startProc);
break;
}
job = job->nxt;
}
return size;
}
int cmptFragmentation(procList * jobs, allocList * mem)
{
allocList* memtrav, * temp;
procList* jobtrav;
jobtrav = jobs;
memtrav = mem;
int freespace = 0, memsize, jobsize;
int i = 0;
while (memtrav->nxt != NULL)
{
if (memtrav->nxt->fk_pid == 0)
{
freespace += (memtrav->nxt->endAlloc - memtrav->nxt->startAlloc);
temp = memtrav->nxt;
memtrav->nxt = memtrav->nxt->nxt; delete temp;
}
memtrav = memtrav->nxt;
}
if (memtrav->fk_pid == 0)
{
freespace += (memtrav->endAlloc - memtrav->startAlloc);
memtrav = memtrav->nxt;
}
memtrav = mem;
while (memtrav != NULL)
{
jobsize = search(jobs, memtrav->fk_pid - 1);
memsize = memtrav->endAlloc - memtrav->startAlloc;
if (memtrav->fk_pid != 0)
{
memtrav->endAlloc = memtrav->startAlloc + jobsize;
}
freespace += (memsize - jobsize);
memtrav = memtrav->nxt;
}
memtrav = mem;
while (memtrav != NULL)
{
if (memtrav->nxt == NULL)
{
memtrav->nxt = new allocList;
memtrav = memtrav->nxt;
memtrav->startAlloc = (char*)malloc(freespace);
memtrav->endAlloc = memtrav->startAlloc + freespace;
memset(memtrav->startAlloc, 0, freespace);
memtrav->fk_pid = 0;
memtrav->nxt = NULL;
break;
}
memtrav = memtrav->nxt;
}
memtrav = mem;
cout << endl << endl << "Defragmentation\nMemory " << "Block\tSize\tJob\tFreeSpace\n";
while (memtrav != NULL)
{
i++;
cout << "\t" << i << "\t" << memtrav->endAlloc - memtrav->startAlloc << "\t" << memtrav->fk_pid
<< "\t" << memtrav->endAlloc - memtrav->startAlloc - search(jobs, memtrav->fk_pid - 1) << endl;
memtrav = memtrav->nxt;
}
while (jobtrav != NULL)
{
if (jobtrav->jobstatus == 0)
{
doFirstFit(jobs, mem);
cmptFragmentation(jobs, mem);
}
jobtrav = jobtrav->nxt;
}
return 0;
}
bool reset(procList* jobs, allocList* mem)
{
procList* tempj = jobs;
allocList* tempa = mem;
while (jobs->nxt != NULL)
{
jobs = jobs->nxt;
free(tempj);
tempj = jobs;
}
free(tempj);
while (mem->nxt != NULL)
{
mem = mem->nxt;
free(tempa);
tempa = mem;
}
free(tempa);
return true;
}
The above working just fine.
My purpose is to change the tank (an object of first class) by another class (the odometer). So I try to passing by reference, its working when I pass directly object to constructor but its doesn't working when I make an object first then passing object by a method(setOdoIndex). Can someone have a way to do make a method to pass these parameters
#include <iostream>
using namespace std;
class FuelGauge {
protected:
double galls;
double check(double) const;
double checkFuel(double) const;
public:
FuelGauge(double galls){
check(galls);
this->galls = galls;
}
FuelGauge(){
*this = FuelGauge(0);
}
double getFuelLeft() const{
return galls;
}
FuelGauge operator++(){
if (galls > 15) throw "Tank max capacity is 15 gallon";
++galls;
return *this;
}
FuelGauge operator--(){
if (galls == 0) throw "Tank is empty";
--galls;
return *this;
}
void refuel(){
galls = 15;
}
};
double FuelGauge::check(double n) const {
if (n < 0) throw "Dont accepted negative value!";
if (n > 15) throw "Tank max capacity is 15 gallon";
return n;
}
class Odometer{
private:
int odo;
FuelGauge &tank;
void calOdo() {
if (odo > 999999) {odo = 0;};
}
public:
Odometer(int odo, FuelGauge &tank):tank(tank) {
this->odo = odo;
this->tank = tank;
}
Odometer():tank(tank) {
odo = 0;
}
int getOdoIndex() const{
return odo;
}
void setOdoIndex(int odo, FuelGauge &tank) {
this->odo = odo;
this->tank = tank;
}
void carDrive() {
--tank;
calOdo();
++odo;
}
};
int main() {
FuelGauge tank;
cout << "--Fill the tank--" << endl;
try {
for (int i = 0; i < 15; i++) {
++tank;
}
}
catch(const char* e) {
cerr << e << '\n';
}
cout << "\n--Car run--" << endl;
Odometer odo1(0, tank);
try {
for(int i = 0; i < 16; i++) {
cout << "Index of odometer: " << odo1.getOdoIndex() << endl;
cout << "Fuel left: " << tank.getFuelLeft() << endl;
odo1.carDrive();
}
}
catch(const char* e) {
cerr << e << '\n';
}
return 0;
}
#include<iostream>
#include<conio.h>
#include <chrono>
#include <ctime>
using namespace std;
typedef std::chrono::high_resolution_clock Clock;
/*struct*/ class Car
{
private:
int carYear;
string carMake;
string carModel;
int carSpeed;
float carGallons;
public:
Car(int cY = 0, string cMa = "", string cMo = "", int cS = 0, float cG = 10)
{
carYear = cY;
carMake = cMa;
carModel = cMo;
carSpeed = cS;
carGallons = cG;
}
Car()
{
carMake = "Bugatti";
carYear = 2020;
carModel = "Chiron";
}
int getCarYear() { return carYear; }
string getCarMake() { return carMake; }
string getCarModel() { return carModel; }
int getCarSpeed() { return carSpeed; }
float getCarGallons() { return carGallons; }
void setCarSpeed(int cS) { carSpeed = cS; }
void setCarGallons(float cG) { carGallons = cG; }
void accelerate()
{
startCar();
if(carGallons>0)
{
carSpeed += 5;
carGallons -= .5;
}
else if (carGallons < 0)
{
carGallons = 0;
cout << "Please refill tank!";
}
}
void brake()
{
startCar();
if(carSpeed>0&&carGallons>0)
{
carSpeed -= 5;
carGallons -= .2;
}
else if(carSpeed<0&&carGallons<0)
{
carSpeed = 0;
cout << "Your car isn't moving!";
}
}
void fillUP()
{
if (carSpeed > 0)
{
cout << "The car is still moving!";
}
else if(carSpeed==0)
{
if (carGallons > 22)
{
cout << "Car is full!";
carGallons = 22;
}
else
{
carGallons += .2;
}
}
}
void startCar(bool carOn=true)
{
while (true)
{
std::chrono::system_clock::time_point then;
auto now = std::chrono::system_clock::now();
auto duration = now - then;
then = now;
if (false) return;
{
auto s = std::chrono::duration_cast<std::chrono::duration<double>>(duration);
carGallons -= s.count() * .05f;
}
}
}
};
int main()
{
bool carOn = false;
Car userCar(2020, "Bugatti", "Chiron");
cout << "\nStart your new " << userCar.getCarYear()<<" "<< userCar.getCarMake() <<" "<< userCar.getCarModel()<<"!";
cout << "\nHit O to start your Engine!";
char ch;
cin >> ch;
if (ch== 'o'|| ch=='O') {
bool carOn = true;
cout << "\nCar is now on! Safe driving!\n";
int c = 0;
while (1)
{
c = 0;
switch (c = _getch())
{
case 32:
userCar.fillUP();
break;
case 72:
cout << userCar.getCarSpeed() << " " << userCar.getCarGallons();
userCar.accelerate();
break;
case 80:
userCar.brake();
break;
case 75:cout << "\nleft"; break;
case 77:cout << "\nright"; break;
default:
cout << " ";
}
}
}
else
{
cout << "\nCar is not on!";
}
return 0;
}
I'm running into an issue where after taking input from the user to turn on their car the inputs freeze up and the switch doesn't accept any other inputs. I know it has something to do with how I'm calling my functions inside the switch but I'm at a loss for how to correct it. Also, I'm fairly certain I've incorrectly implemented my clock inside startCar, it's supposed to subtract gas while the car is on.
I am a beginner with C++ and have tried a few different things, but no matter what I try it doesn’t seem to recognize when a card has already been drawn...
I have tried to utilize to bool isDrawn, but after a few attempts of that with no success I am not 100% sure where to go from here
class Card {
public:
string suitName;
int cardNumber;
void printCard() {
if (cardNumber == 1) {
cout << "Ace";
} else if (cardNumber == 11) {
cout << "Jack";
} else if (cardNumber == 12) {
cout << "Queen";
} else if (cardNumber == 13) {
cout << "King";
} else
cout << cardNumber;
cout << " of " << suitName << endl;
}
bool isDrawn = false;
};
class Deck {
public:
Card deck[52];
void makeDeck(){
int counter = 0;
string suits[] = { "Spades", "Hearts", "Clubs", "Diamonds" };
string face[] = { "Ace", "Jack", "Queen", "King" };
for (int i = 0; i <= 3; i++) {
for (int j = 0; j < 13; j++) {
deck[counter].isDrawn = false;
deck[counter].cardNumber = (j + 1);
deck[counter].suitName = suits[i];
counter++;
}
}
}
Card drawCard() {
int randcard;
do {
randcard = rand() % 52;
} while (deck[randcard].isDrawn == true);
return deck[randcard];
}
};
class Player {
public:
vector<Card> hand;
void setName(string s){
name = s;
}
string printName(){
return name;
}
void printHand() {
for (int i = 0; i < hand.size(); i++){
hand.at(i).printCard();}
}
private:
string name;
};
int main() {
Deck my_deck;
Player p1;
p1.setName("HAL 9000");
cout << p1.printName() << endl;
my_deck.makeDeck();
p1.hand.push_back(my_deck.drawCard());
p1.hand.push_back(my_deck.drawCard());
p1.hand.push_back(my_deck.drawCard());
p1.printHand();
cout << endl;
}
When I use the object function set_and_make_variable I send it a name and value which both work correctly. However then when I go to use show current_variables it acts like I never set the values for both integers, and integers_names. I thought you could modify the variables arrays from the functions associated with the class without references or pointers.
Am I not correct?
void reset_name(string *variable_names)
{
for (int i = 0; i < 100; i++)
{
variable_names[i] = "";
}
}
void reset_int_value(int *variable_value)
{
for (int i = 0; i < 100; i++)
{
variable_value[i] = 0;
}
}
int find_next(string variable_names[100])
{
for (int i = 0; i < 100; i++)
{
if (variable_names[i] == "")
{
return i;
}
}
}
//*****************************************************************
class variables_integers
{
public:
string integer_names[100];
int integers[100];
variables_integers(void);
void set_and_make_variable(string, int);
void show_current_variables(void);
};
variables_integers::variables_integers(void)
{
reset_int_value(integers);
reset_name(integer_names);
}
void variables_integers::show_current_variables(void)
{
cout << "INTEGERS:" << endl;
for (int i = 0; i < (find_next(integer_names)); i++)
{
cout << integer_names[i] << " = " << integers[i] << endl;
}
}
void variables_integers::set_and_make_variable(string name, int value)
{
cout << name << " " << value << endl;
cout << find_next(integer_names) << endl;
integers[find_next(integer_names)] = value;
integer_names[find_next(integer_names)] = name;
}
//*** added code ******
bool operations_and_declerations(string parsed_input[3000], variables variable)
{
if (parsed_input[0] == "int")
{
if (parsed_input[2] == "=")
{
variable.integers.set_and_make_variable(parsed_input[1], atoi(parsed_input[3].c_str()));
}
return true;
}
else if (parsed_input[0] == "string")
{
return true;
}
//else if (parsed_input[0] ==)
else
{
return false;
}
}
In operations_and_declerations(), you sent your variables parameter by value. Hence, the function created a local copy, and only modified that local copy.
You can fix the problem by sending it the parameter by reference. Just modify the function name to:
bool operations_and_declerations(string parsed_input[3000], variables & variable)