SlideShare a Scribd company logo
1 of 14
Download to read offline
C++ code, please help! Troubleshooting and cannot for the life of me figure it out. I am using
Visual Studio Code.
Error message:
ld: Undefined symbols:
parseName(std::__1::basic_stringstream, std::__1::allocator>&), referenced from:
parseAssignments(std::__1::basic_stringstream, std::__1::allocator>&) in module-a187a7.o
SymbolTable::init(), referenced from:
_main in module-a187a7.o
parseAssignments(std::__1::basic_stringstream, std::__1::allocator>&) in module-a187a7.o
SymbolTable::insert(std::__1::basic_string, std::__1::allocator>, int), referenced from:
parseAssignments(std::__1::basic_stringstream, std::__1::allocator>&) in module-a187a7.o
SubExpression::parse(std::__1::basic_stringstream, std::__1::allocator>&), referenced from:
_main in module-a187a7.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Done] exited with code=1 in 1.478 seconds
divide.h
class Divide : public SubExpression
{
public:
//define the default construtor
Divide(Expression* left, Expression* right) : SubExpression(left, right)
{
}
//define the function evaluate()
int evaluate()
{
//divide the value of left and value of the right
//and return the value.
return left->evaluate() / right->evaluate();
}
};
expression.h
// Expression
class Expression
{
public:
//declare a virtual function evaluate()
virtual int evaluate() = 0;
};
literal.h
//Operand
class Literal : public Operand
{
public:
//define the construtor
Literal(int value)
{
this->value = value;
}
//define the function evaluate()
//returns the value
int evaluate()
{
return value;
}
private:
int value;
};
minus.h
//define the class Minus subclass of the SubExpression
class Minus : public SubExpression
{
public:
//define the default construtor
Minus(Expression* left, Expression* right) : SubExpression(left, right)
{
}
//define the function evaluate()
int evaluate()
{
//subtract the value of right from the value of the left
//and return the value.
return left->evaluate() - right->evaluate();
}
};
module.cpp
#include
#include
#include
#include
#include
using namespace std;
#include "expression.h"
#include "subexpression.h"
#include "symboltable.h"
#include "parse.h"
//create an object of SymbolTable
SymbolTable symbolTable;
//prototype of the function
void parseAssignments(stringstream& in);
//define main function
int main()
{
// declare the variables
Expression* expression;
char paren, comma;
string line;
// create an input file stream
ifstream fin("input.txt");
// check, if the file is not opened
//then display a error message
if (!fin.is_open())
perror("error while opening file");
//use a loop, to read the content from the file
while (getline(fin, line))
{
symbolTable.init();
if (!fin)
break;
stringstream in(line, ios_base::in);
in >> paren;
cout << line << " ";
expression = SubExpression::parse(in);
in >> comma;
//call the function
parseAssignments(in);
//Display the result
int result = expression->evaluate();
cout << "Value = " << result << endl;
}
system("pause");
return 0;
}
//definition of the function parseAssignments()
void parseAssignments(stringstream& in)
{
char assignop, delimiter;
string variable;
int value;
symbolTable.init();
do
{
variable = parseName(in);
in >> ws >> assignop >> value >> delimiter;
symbolTable.insert(variable, value);
}
while (delimiter == ',');
}
operand.cpp
#include
#include
#include
#include
using namespace std;
#include "expression.h"
#include "subexpression.h"
#include "operand.h"
#include "variable.h"
#include "literal.h"
#include "parse.h"
#include
//definition of the function parse()
Expression* Operand::parse(stringstream& in)
{
char paren;
double value;
in >> ws;
if (isdigit(in.peek()))
{
in >> value;
Expression* literal = new Literal(value);
return literal;
}
if (in.peek() == '(')
{
in >> paren;
return SubExpression::parse(in);
}
else
return new Variable(parseName(in));
return 0;
}
operand.h
//define the class Operand subclass of the Expression
class Operand : public Expression
{
public:
//declare a static function parse()
static Expression* parse(stringstream& in);
};
parse.cpp
#include
#include
#include
#include
using namespace std;
#include "parse.h"
//definition of the function parseName()
string parseName(stringstream &in)
{
char alnum;
string name = "";
in >> ws;
while (isalnum(in.peek()))
{
in >> alnum;
name += alnum;
}
return name;
}
parse.h
#include
#include
//declare a function parseName()
string parseName(stringstream &in);
plus.h
//define the class Plus subclass of the SubExpression
class Plus: public SubExpression
{
public:
//define the default construtor
Plus(Expression* left, Expression* right): SubExpression(left, right)
{
}
//define the function evaluate()
int evaluate()
{
//adds the value of left and value of the right
//and return the value.
return left->evaluate() + right->evaluate();
}
};
subexpression.cpp
subexpression.cpp
#include
using namespace std;
#include "expression.h"
#include "subexpression.h"
#include "operand.h"
#include "plus.h"
#include "minus.h"
#include "times.h"
#include "divide.h"
#include
//define the constructor
SubExpression::SubExpression(Expression* left, Expression* right)
{
this->left = left;
this->right = right;
}
//definition of the class parse()
Expression* SubExpression::parse(stringstream& in)
{
Expression* left;
Expression* right;
char operation, paren;
//read the Operand
left = Operand::parse(in);
//read the operation
in >> operation;
//read the Operand
right = Operand::parse(in);
//read the paren
in >> paren;
switch (operation)
{
case '+':
return new Plus(left, right);
case '-':
return new Minus(left, right);
case '*':
return new Times(left, right);
case '/':
return new Divide(left, right);
}
system("pause");
return 0;
}
subexpression.h
//define the class SubExpression subclass of the Expression
class SubExpression : public Expression
{
public:
//constructor
SubExpression(Expression* left, Expression* right);
//declare a static function parse()
static Expression* parse(stringstream& in);
protected:
//declare the variables
Expression* left;
Expression* right;
};
symboltable.cpp
#include
#include
using namespace std;
#include "symboltable.h"
//definition of the function insert()
void SymbolTable::insert(string variable, int value)
{
//push the symbol in to the vector
const Symbol& symbol = Symbol(variable, value);
elements.push_back(symbol);
}
//definition of the function lookUp()
int SymbolTable::lookUp(string variable) const
{
//search in the vector and return the value.
for (int i = 0; i < elements.size(); i++)
if (elements[i].variable == variable)
return elements[i].value;
return -1;
}
void SymbolTable::init()
{
elements.clear();
}
symboltable.h
//define the class SubExpression
class SymbolTable
{
public:
//constructor
SymbolTable() {}
//declare the function
void insert(string variable, int value);
int lookUp(string variable) const;
void init();
private:
//define the structure Symbol
struct Symbol
{
Symbol(string variable, int value)
{
this->variable = variable;
this->value = value;
}
string variable;
int value;
};
//create a vector of type Symbol
vector elements;
};
times.h
//define the class Minus subclass of the SubExpression
class Times : public SubExpression
{
public:
//define the default construtor
Times(Expression* left, Expression* right) : SubExpression(left, right)
{
}
//define the function evaluate()
int evaluate()
{
//multiple the value of right and value of the left
//and return the value.
return left->evaluate() * right->evaluate();
}
};
variable.cpp
#include
#include
using namespace std;
#include "expression.h"
#include "operand.h"
#include "variable.h"
#include "symboltable.h"
//create an object of SymbolTable
extern SymbolTable symbolTable;
//definition of the function evaluate()
int Variable::evaluate()
{
//return the name from the symbolTable
return symbolTable.lookUp(name);
}
variable.h
#include
#include
using namespace std;
//define the class Variable subclass of the Operand
class Variable : public Operand
{
public:
//define the construtor
Variable(string name)
{
this->name = name;
}
//define the function evaluate()
int Variable::evaluate();
private:
string name;
};
input.txt (file)
((a + 4) ~), a = 3;
((x * 2.6) + (y - 3)), x = 1.5, y = 6;
(( 7 / z_1) + (z_1 ^ 2)), z_1 = 2;
((6 % b) < 5), b = 4;
(c > d), c = 9, d = 7;
(e & 8), e = 5;
(f ? 1 2), f = 0;
(g # 1 2 3), g = 2;
(tt + ss), tt = 2;
(aa + 1), aa = 1, aa = 2;
The statements of that expression language consist of an arithmetic expression followed by a list
of assignments. Assignments are separated from the expression and each other by commas. A
semicolon terminates the expression. The arithmetic expressions are fully parenthesized infix
expressions containing integer literals and variables. The syntax of a single input file line is
described grammar below: statement expression ', ' assignments ' ' expression ' (' operand
operator operand ') ' operator '+' I '-' operand literal | variable | expression assignments
assignments ', ' assignment | assignment assignment variable '=' literal statement expression ', '
assignments ' ; ' expression ' (' operand operator operand ') ' operator '+' | '-' operand literal |
variable | expression assignments assignments ' ' assignment | assignment assignment variable
'=' literal In the above grammar, terminal symbols are upper case names or character literals
shown in blue and nonterminal symbols are lower case names shown in red. EBNF
metacharacters are shown in black. Tokens can be separated by any number of spaces. Tokens
can be separated by any number of spaces. Variable names begin with an alphabetic character,
followed by any number of alphanumeric characters. Variable names are case sensitive. The
regular expressions defining the variables and literal tokens are the following:
variableliteral[azAZ][azAZ09][09]+ The program reads in the arithmetic expression and encodes
the expression as a binary tree. After the expression has been read in, the variable assignments
are read in and the variables and their values of the variables are placed into the symbol table.
Finally the expression is evaluated recursively. Your first task is to modify the program so that it
will parse additional types of expressions defined by the expanded grammar shown below with
the additions to the grammar highlighted in yellow: statement expression ',' assignments ' ;'
expression '(' ') ' expressions unary_expression | binary_expression | ternary_expression |
quaternary_expression I operand unary_expression expression ' ' binary_expression expression
binary_operator expression ternary_expression expression '?' expression expression
quaternary_expression expression '#' expression expression expression operand literal |
variable | expression assignments assignments ',' assignment | assignment assignment variable
'=' literal The semantics of the additional binary arithmetic operators are as follows: *
Multiplication / Division Remainder Exponentiation Although two of the three additional
binary operators are customarily relational operators in most languages, that is not true in this
language. The semantics of all three of those operators are as follows: < Minimum (Evaluates to
the minimum of the left and right operand) > Maximum (Evaluates to the maximum of the left
and right operand) & Average (Evaluates to the average of the left and right operand) The single
unary operator is the negation operator. Unlike the unary minus in most languages, it is a postfix
operator rather than a prefix one. The single ternary operator? is the conditional expression
operator. Unlike the conditional expression operator in C++ and Java, no colon separates the
second and third operands. This expression is evaluated as follows. If the expression to the left of
the operator ? is not 0 , the value of the expression is the value of the first expression after the
operator ?. If it is 0 , the value of the expression is the value of the second expression after the
operator? The single quaternary operator # is a variation of the typical conditional expression
operator. Like the ternary conditional expression operator, the remaining three operands are
delimited only by whitespace. This expression is evaluated as follows. If the expression to the
left of the operator # is less than 0 , the value of the expression is the value of the first
expression after the operator #. If it is equal to 0 , the value of the expression is the value of the
second expression after the operator #. If it is greater than 0 , the value of the expression is the
value of the third expression after the operator #.
The second task is to modifier the variable token so that underscores are permitted in all but the
first character and modify the literal token so that it accepts unsigned floating point literals.
Assignments also should be modified to allow assignment to values that are should also floating
point rather than just integers. The final task is to make the following modifications: - The
symbol table should be initialized before each statement is evaluated, so that variables that are
reused do not contain the value from a previous statement - Statements containing uninitialized
variables should be reported as an error - A variable initialized more than once in a statement
should be reported as an error (Creating an exception class to accommodate this error and the
previous one is the recommended approach) You may assume that all input is syntactically
correct. No checks for syntax errors is required. Each new class must be in a separate.h and.cpp
pair of files. If all the functions in a class are one line functions, they can be implemented inline
in .h file and the .cpp file can be omitted.

More Related Content

Similar to C++ code, please help! Troubleshooting and cannot for the life of me.pdf

Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdfaathmaproducts
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdfaathiauto
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programmingIcaii Infotech
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notesGOKULKANNANMMECLECTC
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it outrajatryadav22
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdfNehaSpillai1
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptxhara69
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 

Similar to C++ code, please help! Troubleshooting and cannot for the life of me.pdf (20)

Function in c program
Function in c programFunction in c program
Function in c program
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Function in c
Function in cFunction in c
Function in c
 
Function in c
Function in cFunction in c
Function in c
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Functions
FunctionsFunctions
Functions
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
C programming
C programmingC programming
C programming
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
 
Pointers
PointersPointers
Pointers
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 

More from rahulfancycorner21

Consider a world in which there are two nations � the US and China, ea.pdf
Consider a world in which there are two nations � the US and China, ea.pdfConsider a world in which there are two nations � the US and China, ea.pdf
Consider a world in which there are two nations � the US and China, ea.pdfrahulfancycorner21
 
Configure iptables to ACCEPT packets by defaultConfigure iptables .pdf
Configure iptables to ACCEPT packets by defaultConfigure iptables .pdfConfigure iptables to ACCEPT packets by defaultConfigure iptables .pdf
Configure iptables to ACCEPT packets by defaultConfigure iptables .pdfrahulfancycorner21
 
CIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdf
CIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdfCIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdf
CIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdfrahulfancycorner21
 
CLIENT APPLICATION Create a standalone, interactive, and fully com.pdf
CLIENT APPLICATION Create a standalone, interactive, and fully com.pdfCLIENT APPLICATION Create a standalone, interactive, and fully com.pdf
CLIENT APPLICATION Create a standalone, interactive, and fully com.pdfrahulfancycorner21
 
Case Study Makati CityMakati City is one of the sixteen cit.pdf
Case Study Makati CityMakati City is one of the sixteen cit.pdfCase Study Makati CityMakati City is one of the sixteen cit.pdf
Case Study Makati CityMakati City is one of the sixteen cit.pdfrahulfancycorner21
 
Clara fears she may have made a mistake in how she handled the expen.pdf
Clara fears she may have made a mistake in how she handled the expen.pdfClara fears she may have made a mistake in how she handled the expen.pdf
Clara fears she may have made a mistake in how she handled the expen.pdfrahulfancycorner21
 
Chapter 11 Conrols for Information Security11.4 Which preventive, .pdf
Chapter 11 Conrols for Information Security11.4 Which preventive, .pdfChapter 11 Conrols for Information Security11.4 Which preventive, .pdf
Chapter 11 Conrols for Information Security11.4 Which preventive, .pdfrahulfancycorner21
 
Case 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdf
Case 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdfCase 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdf
Case 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdfrahulfancycorner21
 
CASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdf
CASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdfCASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdf
CASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdfrahulfancycorner21
 
can i have the Answers of the above questions 1. Compare and contr.pdf
can i have the Answers of the above questions 1. Compare and contr.pdfcan i have the Answers of the above questions 1. Compare and contr.pdf
can i have the Answers of the above questions 1. Compare and contr.pdfrahulfancycorner21
 
Case 1 Why shareholders wealth maximization value maximization is c.pdf
Case 1 Why shareholders wealth maximization value maximization is c.pdfCase 1 Why shareholders wealth maximization value maximization is c.pdf
Case 1 Why shareholders wealth maximization value maximization is c.pdfrahulfancycorner21
 
Capstone Project E-Commerce Application with Firebase Firestore Obj.pdf
Capstone Project E-Commerce Application with Firebase Firestore Obj.pdfCapstone Project E-Commerce Application with Firebase Firestore Obj.pdf
Capstone Project E-Commerce Application with Firebase Firestore Obj.pdfrahulfancycorner21
 
Can you draw a database design Entity relationship ERand the rela.pdf
Can you draw a database design Entity relationship ERand the rela.pdfCan you draw a database design Entity relationship ERand the rela.pdf
Can you draw a database design Entity relationship ERand the rela.pdfrahulfancycorner21
 
Business PlanA business plan is any simple plan, not only limited .pdf
Business PlanA business plan is any simple plan, not only limited .pdfBusiness PlanA business plan is any simple plan, not only limited .pdf
Business PlanA business plan is any simple plan, not only limited .pdfrahulfancycorner21
 
Can we please draw this BPM process roughly on paper and post a pict.pdf
Can we please draw this BPM process roughly on paper and post a pict.pdfCan we please draw this BPM process roughly on paper and post a pict.pdf
Can we please draw this BPM process roughly on paper and post a pict.pdfrahulfancycorner21
 
Can we draw this BPM on paper showing shapes arrows and connectors .pdf
Can we draw this BPM on paper showing shapes arrows and connectors .pdfCan we draw this BPM on paper showing shapes arrows and connectors .pdf
Can we draw this BPM on paper showing shapes arrows and connectors .pdfrahulfancycorner21
 
Can u give a CORAS ASSEST DIAGRAM for the following case study - The.pdf
Can u give a CORAS ASSEST DIAGRAM for the following case study - The.pdfCan u give a CORAS ASSEST DIAGRAM for the following case study - The.pdf
Can u give a CORAS ASSEST DIAGRAM for the following case study - The.pdfrahulfancycorner21
 
BUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdf
BUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdfBUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdf
BUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdfrahulfancycorner21
 

More from rahulfancycorner21 (18)

Consider a world in which there are two nations � the US and China, ea.pdf
Consider a world in which there are two nations � the US and China, ea.pdfConsider a world in which there are two nations � the US and China, ea.pdf
Consider a world in which there are two nations � the US and China, ea.pdf
 
Configure iptables to ACCEPT packets by defaultConfigure iptables .pdf
Configure iptables to ACCEPT packets by defaultConfigure iptables .pdfConfigure iptables to ACCEPT packets by defaultConfigure iptables .pdf
Configure iptables to ACCEPT packets by defaultConfigure iptables .pdf
 
CIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdf
CIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdfCIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdf
CIS611 SS Chung Lab Assignment 2 Implementing Big Data Processing Pipe.pdf
 
CLIENT APPLICATION Create a standalone, interactive, and fully com.pdf
CLIENT APPLICATION Create a standalone, interactive, and fully com.pdfCLIENT APPLICATION Create a standalone, interactive, and fully com.pdf
CLIENT APPLICATION Create a standalone, interactive, and fully com.pdf
 
Case Study Makati CityMakati City is one of the sixteen cit.pdf
Case Study Makati CityMakati City is one of the sixteen cit.pdfCase Study Makati CityMakati City is one of the sixteen cit.pdf
Case Study Makati CityMakati City is one of the sixteen cit.pdf
 
Clara fears she may have made a mistake in how she handled the expen.pdf
Clara fears she may have made a mistake in how she handled the expen.pdfClara fears she may have made a mistake in how she handled the expen.pdf
Clara fears she may have made a mistake in how she handled the expen.pdf
 
Chapter 11 Conrols for Information Security11.4 Which preventive, .pdf
Chapter 11 Conrols for Information Security11.4 Which preventive, .pdfChapter 11 Conrols for Information Security11.4 Which preventive, .pdf
Chapter 11 Conrols for Information Security11.4 Which preventive, .pdf
 
Case 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdf
Case 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdfCase 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdf
Case 12�1Carson ManorIn late November, Ms. Elaine Taylor, direct.pdf
 
CASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdf
CASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdfCASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdf
CASE STUDY 1 Alternative Water Supply Gordon Rivers, the city manage.pdf
 
can i have the Answers of the above questions 1. Compare and contr.pdf
can i have the Answers of the above questions 1. Compare and contr.pdfcan i have the Answers of the above questions 1. Compare and contr.pdf
can i have the Answers of the above questions 1. Compare and contr.pdf
 
Case 1 Why shareholders wealth maximization value maximization is c.pdf
Case 1 Why shareholders wealth maximization value maximization is c.pdfCase 1 Why shareholders wealth maximization value maximization is c.pdf
Case 1 Why shareholders wealth maximization value maximization is c.pdf
 
Capstone Project E-Commerce Application with Firebase Firestore Obj.pdf
Capstone Project E-Commerce Application with Firebase Firestore Obj.pdfCapstone Project E-Commerce Application with Firebase Firestore Obj.pdf
Capstone Project E-Commerce Application with Firebase Firestore Obj.pdf
 
Can you draw a database design Entity relationship ERand the rela.pdf
Can you draw a database design Entity relationship ERand the rela.pdfCan you draw a database design Entity relationship ERand the rela.pdf
Can you draw a database design Entity relationship ERand the rela.pdf
 
Business PlanA business plan is any simple plan, not only limited .pdf
Business PlanA business plan is any simple plan, not only limited .pdfBusiness PlanA business plan is any simple plan, not only limited .pdf
Business PlanA business plan is any simple plan, not only limited .pdf
 
Can we please draw this BPM process roughly on paper and post a pict.pdf
Can we please draw this BPM process roughly on paper and post a pict.pdfCan we please draw this BPM process roughly on paper and post a pict.pdf
Can we please draw this BPM process roughly on paper and post a pict.pdf
 
Can we draw this BPM on paper showing shapes arrows and connectors .pdf
Can we draw this BPM on paper showing shapes arrows and connectors .pdfCan we draw this BPM on paper showing shapes arrows and connectors .pdf
Can we draw this BPM on paper showing shapes arrows and connectors .pdf
 
Can u give a CORAS ASSEST DIAGRAM for the following case study - The.pdf
Can u give a CORAS ASSEST DIAGRAM for the following case study - The.pdfCan u give a CORAS ASSEST DIAGRAM for the following case study - The.pdf
Can u give a CORAS ASSEST DIAGRAM for the following case study - The.pdf
 
BUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdf
BUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdfBUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdf
BUsiness law9.3 Implied-in-Fact Contract For six years, Lee Marvin.pdf
 

Recently uploaded

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

C++ code, please help! Troubleshooting and cannot for the life of me.pdf

  • 1. C++ code, please help! Troubleshooting and cannot for the life of me figure it out. I am using Visual Studio Code. Error message: ld: Undefined symbols: parseName(std::__1::basic_stringstream, std::__1::allocator>&), referenced from: parseAssignments(std::__1::basic_stringstream, std::__1::allocator>&) in module-a187a7.o SymbolTable::init(), referenced from: _main in module-a187a7.o parseAssignments(std::__1::basic_stringstream, std::__1::allocator>&) in module-a187a7.o SymbolTable::insert(std::__1::basic_string, std::__1::allocator>, int), referenced from: parseAssignments(std::__1::basic_stringstream, std::__1::allocator>&) in module-a187a7.o SubExpression::parse(std::__1::basic_stringstream, std::__1::allocator>&), referenced from: _main in module-a187a7.o clang: error: linker command failed with exit code 1 (use -v to see invocation) [Done] exited with code=1 in 1.478 seconds divide.h class Divide : public SubExpression { public: //define the default construtor Divide(Expression* left, Expression* right) : SubExpression(left, right) { } //define the function evaluate() int evaluate() { //divide the value of left and value of the right //and return the value. return left->evaluate() / right->evaluate(); }
  • 2. }; expression.h // Expression class Expression { public: //declare a virtual function evaluate() virtual int evaluate() = 0; }; literal.h //Operand class Literal : public Operand { public: //define the construtor Literal(int value) { this->value = value; } //define the function evaluate() //returns the value int evaluate() { return value; } private: int value; }; minus.h //define the class Minus subclass of the SubExpression class Minus : public SubExpression { public: //define the default construtor
  • 3. Minus(Expression* left, Expression* right) : SubExpression(left, right) { } //define the function evaluate() int evaluate() { //subtract the value of right from the value of the left //and return the value. return left->evaluate() - right->evaluate(); } }; module.cpp #include #include #include #include #include using namespace std; #include "expression.h" #include "subexpression.h" #include "symboltable.h" #include "parse.h" //create an object of SymbolTable SymbolTable symbolTable; //prototype of the function void parseAssignments(stringstream& in); //define main function int main() { // declare the variables Expression* expression; char paren, comma; string line; // create an input file stream ifstream fin("input.txt");
  • 4. // check, if the file is not opened //then display a error message if (!fin.is_open()) perror("error while opening file"); //use a loop, to read the content from the file while (getline(fin, line)) { symbolTable.init(); if (!fin) break; stringstream in(line, ios_base::in); in >> paren; cout << line << " "; expression = SubExpression::parse(in); in >> comma; //call the function parseAssignments(in); //Display the result int result = expression->evaluate(); cout << "Value = " << result << endl; } system("pause"); return 0; } //definition of the function parseAssignments() void parseAssignments(stringstream& in) { char assignop, delimiter; string variable; int value; symbolTable.init(); do { variable = parseName(in); in >> ws >> assignop >> value >> delimiter; symbolTable.insert(variable, value);
  • 5. } while (delimiter == ','); } operand.cpp #include #include #include #include using namespace std; #include "expression.h" #include "subexpression.h" #include "operand.h" #include "variable.h" #include "literal.h" #include "parse.h" #include //definition of the function parse() Expression* Operand::parse(stringstream& in) { char paren; double value; in >> ws; if (isdigit(in.peek())) { in >> value; Expression* literal = new Literal(value); return literal; } if (in.peek() == '(') { in >> paren; return SubExpression::parse(in); } else
  • 6. return new Variable(parseName(in)); return 0; } operand.h //define the class Operand subclass of the Expression class Operand : public Expression { public: //declare a static function parse() static Expression* parse(stringstream& in); }; parse.cpp #include #include #include #include using namespace std; #include "parse.h" //definition of the function parseName() string parseName(stringstream &in) { char alnum; string name = ""; in >> ws; while (isalnum(in.peek())) { in >> alnum; name += alnum; } return name; } parse.h #include
  • 7. #include //declare a function parseName() string parseName(stringstream &in); plus.h //define the class Plus subclass of the SubExpression class Plus: public SubExpression { public: //define the default construtor Plus(Expression* left, Expression* right): SubExpression(left, right) { } //define the function evaluate() int evaluate() { //adds the value of left and value of the right //and return the value. return left->evaluate() + right->evaluate(); } }; subexpression.cpp subexpression.cpp #include using namespace std; #include "expression.h" #include "subexpression.h" #include "operand.h" #include "plus.h" #include "minus.h" #include "times.h" #include "divide.h" #include //define the constructor
  • 8. SubExpression::SubExpression(Expression* left, Expression* right) { this->left = left; this->right = right; } //definition of the class parse() Expression* SubExpression::parse(stringstream& in) { Expression* left; Expression* right; char operation, paren; //read the Operand left = Operand::parse(in); //read the operation in >> operation; //read the Operand right = Operand::parse(in); //read the paren in >> paren; switch (operation) { case '+': return new Plus(left, right); case '-': return new Minus(left, right); case '*': return new Times(left, right); case '/': return new Divide(left, right); } system("pause"); return 0; } subexpression.h //define the class SubExpression subclass of the Expression
  • 9. class SubExpression : public Expression { public: //constructor SubExpression(Expression* left, Expression* right); //declare a static function parse() static Expression* parse(stringstream& in); protected: //declare the variables Expression* left; Expression* right; }; symboltable.cpp #include #include using namespace std; #include "symboltable.h" //definition of the function insert() void SymbolTable::insert(string variable, int value) { //push the symbol in to the vector const Symbol& symbol = Symbol(variable, value); elements.push_back(symbol); } //definition of the function lookUp() int SymbolTable::lookUp(string variable) const { //search in the vector and return the value. for (int i = 0; i < elements.size(); i++) if (elements[i].variable == variable) return elements[i].value; return -1; } void SymbolTable::init() {
  • 10. elements.clear(); } symboltable.h //define the class SubExpression class SymbolTable { public: //constructor SymbolTable() {} //declare the function void insert(string variable, int value); int lookUp(string variable) const; void init(); private: //define the structure Symbol struct Symbol { Symbol(string variable, int value) { this->variable = variable; this->value = value; } string variable; int value; }; //create a vector of type Symbol vector elements; }; times.h //define the class Minus subclass of the SubExpression class Times : public SubExpression { public: //define the default construtor
  • 11. Times(Expression* left, Expression* right) : SubExpression(left, right) { } //define the function evaluate() int evaluate() { //multiple the value of right and value of the left //and return the value. return left->evaluate() * right->evaluate(); } }; variable.cpp #include #include using namespace std; #include "expression.h" #include "operand.h" #include "variable.h" #include "symboltable.h" //create an object of SymbolTable extern SymbolTable symbolTable; //definition of the function evaluate() int Variable::evaluate() { //return the name from the symbolTable return symbolTable.lookUp(name); } variable.h #include #include using namespace std; //define the class Variable subclass of the Operand class Variable : public Operand {
  • 12. public: //define the construtor Variable(string name) { this->name = name; } //define the function evaluate() int Variable::evaluate(); private: string name; }; input.txt (file) ((a + 4) ~), a = 3; ((x * 2.6) + (y - 3)), x = 1.5, y = 6; (( 7 / z_1) + (z_1 ^ 2)), z_1 = 2; ((6 % b) < 5), b = 4; (c > d), c = 9, d = 7; (e & 8), e = 5; (f ? 1 2), f = 0; (g # 1 2 3), g = 2; (tt + ss), tt = 2; (aa + 1), aa = 1, aa = 2; The statements of that expression language consist of an arithmetic expression followed by a list of assignments. Assignments are separated from the expression and each other by commas. A semicolon terminates the expression. The arithmetic expressions are fully parenthesized infix expressions containing integer literals and variables. The syntax of a single input file line is described grammar below: statement expression ', ' assignments ' ' expression ' (' operand operator operand ') ' operator '+' I '-' operand literal | variable | expression assignments assignments ', ' assignment | assignment assignment variable '=' literal statement expression ', ' assignments ' ; ' expression ' (' operand operator operand ') ' operator '+' | '-' operand literal | variable | expression assignments assignments ' ' assignment | assignment assignment variable '=' literal In the above grammar, terminal symbols are upper case names or character literals shown in blue and nonterminal symbols are lower case names shown in red. EBNF metacharacters are shown in black. Tokens can be separated by any number of spaces. Tokens can be separated by any number of spaces. Variable names begin with an alphabetic character,
  • 13. followed by any number of alphanumeric characters. Variable names are case sensitive. The regular expressions defining the variables and literal tokens are the following: variableliteral[azAZ][azAZ09][09]+ The program reads in the arithmetic expression and encodes the expression as a binary tree. After the expression has been read in, the variable assignments are read in and the variables and their values of the variables are placed into the symbol table. Finally the expression is evaluated recursively. Your first task is to modify the program so that it will parse additional types of expressions defined by the expanded grammar shown below with the additions to the grammar highlighted in yellow: statement expression ',' assignments ' ;' expression '(' ') ' expressions unary_expression | binary_expression | ternary_expression | quaternary_expression I operand unary_expression expression ' ' binary_expression expression binary_operator expression ternary_expression expression '?' expression expression quaternary_expression expression '#' expression expression expression operand literal | variable | expression assignments assignments ',' assignment | assignment assignment variable '=' literal The semantics of the additional binary arithmetic operators are as follows: * Multiplication / Division Remainder Exponentiation Although two of the three additional binary operators are customarily relational operators in most languages, that is not true in this language. The semantics of all three of those operators are as follows: < Minimum (Evaluates to the minimum of the left and right operand) > Maximum (Evaluates to the maximum of the left and right operand) & Average (Evaluates to the average of the left and right operand) The single unary operator is the negation operator. Unlike the unary minus in most languages, it is a postfix operator rather than a prefix one. The single ternary operator? is the conditional expression operator. Unlike the conditional expression operator in C++ and Java, no colon separates the second and third operands. This expression is evaluated as follows. If the expression to the left of the operator ? is not 0 , the value of the expression is the value of the first expression after the operator ?. If it is 0 , the value of the expression is the value of the second expression after the operator? The single quaternary operator # is a variation of the typical conditional expression operator. Like the ternary conditional expression operator, the remaining three operands are delimited only by whitespace. This expression is evaluated as follows. If the expression to the left of the operator # is less than 0 , the value of the expression is the value of the first expression after the operator #. If it is equal to 0 , the value of the expression is the value of the second expression after the operator #. If it is greater than 0 , the value of the expression is the value of the third expression after the operator #. The second task is to modifier the variable token so that underscores are permitted in all but the first character and modify the literal token so that it accepts unsigned floating point literals.
  • 14. Assignments also should be modified to allow assignment to values that are should also floating point rather than just integers. The final task is to make the following modifications: - The symbol table should be initialized before each statement is evaluated, so that variables that are reused do not contain the value from a previous statement - Statements containing uninitialized variables should be reported as an error - A variable initialized more than once in a statement should be reported as an error (Creating an exception class to accommodate this error and the previous one is the recommended approach) You may assume that all input is syntactically correct. No checks for syntax errors is required. Each new class must be in a separate.h and.cpp pair of files. If all the functions in a class are one line functions, they can be implemented inline in .h file and the .cpp file can be omitted.