Question: code this using c++ . please help i posted this 2 times but both programm not working and it is not also clear. please code
code this using c++ . please help i posted this 2 times but both programm not working and it is not also clear. please code this in less complicated way thanks.
inputfile.txt:
12 add three -4 7 sub mul j 200 3.5 div here 33 7
In this exercise, you are to read in a line from an input file, ex18_inputfile.txt from the Folder Files->Exercise Input Files ex18_inputfile.txt
After downloading the file, it should be placed in the same directory as your source cpp file.
Read in the line from ex18_inputfile.txt using getline() and determine the type of each token in the line. There are 3 possible token types: integer, operator, and junk. If it is an integer, insert it in an array of integers. When the entire input line has been read in, print out the array of integers and the statistics of the tokens to the screen (using cout). Finally, sort this array (using selection sort as given in the lecture) and then print out the new sorted array of integers to the screen. You may assume that there will never be more than 100 integers. So your array size can be set to 100.
In addition to the main() function, your program should have at least 2 other functions, namely:
- void sort(int array[]) - sorts the argument integer array. The array is modified and sorted by the function.
- tokenType getTokenType(string s) - returns the type of the token from the argument string s. Note that tokenType is an enum (enumerated type)
Note that all operators are strictly 3-letters long. That is, 'add' is an operator, but 'adds' is junk!
Example line from ex18_inputfile.txt:
12 add three -4 7 sub mul j 200 3.5 div here 33 7
The output will be:
Token #0: 12 (integer)
Token #1: add (operator)
Token #2: three (junk)
Token #3: -4 (integer)
Token #4: 7 (integer)
Token #5: sub (operator)
Token #6: mul (operator)
Token #7: j (junk)
Token #8: 200 (integer)
Token #9: 3.5 (junk)
Token #10: div (operator)
Token #11: here (junk)
Token #12: 33 (integer)
Token #13: 7 (integer)
Unsorted integer array:
12 -4 7 200 33 7
Stats of the input: 6 integers, 4 operators, and 4 junks
Sorted integer array:
-4 7 7 12 33 200
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
