The assignment is to read in the source code of a C++ program (two are provided)
ID: 652621 • Letter: T
Question
The assignment is to read in the source code of a C++ program (two are provided) and find all of the assignment statements '='. From each of these you should extract the variable to the left of the = operator and all of the variables in the expression on the right-hand side. You may assume that no variable contains an embedded blank and that each statement is on a line by itself.
Input
1. From the user (keyboard): the name of the input file to process.
2. From the input file: a syntactically correct C++ program.
Output
Print out each assignment statement, and next to it the variables that you have extracted. The labeled output should be printed to a file called "Parse_out.txt".
Sample Output:
ASSIGNMENT STATEMENTS LEFT RIGHT
one = data; one data
x = 5.6; x
test = sqrt(x + 5.4) + one/x; test x, one, x
x = rec + num * (age - 10); x rec, num, age
Deliverables
1. A list of your program..
2. Parse_out.txt
Explanation / Answer
Parsing variables:
string S=" S1="one", S2="data", s3,s4;
cout<<S<<endl;
cout<<left;
cout<<setw(40)<<S1;
cout<<right;
cout<<setw(40)<<S2<<endl;
S="x = 5.6";
cout<<S<<endl;
S1="x";
cout<<left;
cout<<setw(40)<<S1;
cout<<right;
cout<<setw(40)<<endl;
S="test = sqrt(x + 5.4) + one/x";
cout<<S<<endl;
S1="test",S2="x";S3="one";
cout<<left;
cout<<setw(40)<<S1;
cout<<right;
cout<<setw(40)<<S2<<","<<S3<<","<<S2<<endl;
S="x = rec + num * (age - 10)";
cout<<S<<endl;
S1="x",S2="rec",S3="num";S4="age";
cout<<left;
cout<<setw(40)<<S1;
cout<<right;
cout<<setw(40)<<S2<<","<<S3<<","<<S4<<endl;
______________________________________________________________________
//To output
ifstream In;
In.open("Parse_out.txt");
In>>one>>data;
ofstream Out("Parse_out.txt");
out.close();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.