commands1.txt SCANC1=C(C(C=C(C1O)Cl)O)Cl JOIN[NH4+] PRINT CLEAR JOINN+(C1=CC) PRINT TEST(COP(=O)(O)OP(=O) commands2.txt SCANCCC(C)(C(C(=O)O)O)O PRINT READ11 SCANC1=C(C(C=C(C1O)Cl)O)Cl...

1 answer below »
This needs to be done in c++ and I would prefer commented code


commands1.txt SCANC1=C(C(C=C(C1O)Cl)O)Cl JOIN[NH4+] PRINT CLEAR JOINN+(C1=CC) PRINT TEST(COP(=O)(O)OP(=O) commands2.txt SCANCCC(C)(C(C(=O)O)O)O PRINT READ11 SCANC1=C(C(C=C(C1O)Cl)O)Cl JOIN[NH4+] PRINT CLEAR JOINO PRINT TESTCC(C)(COP(=O)(O)OP(=O)(O)OCC1C(C(C(O1)N2C=NC3=C(N=CN=C32)N)O)OP(=O)(O)O)C(C(=O)NCCC(=O)NCCSC(=O)CC(C)(CC(=O)O)O)O JOINCCC(C)C(C(=O)NCC(=O)O)NC(=O)C(CS)NC(=O)C(C(C)O)NC(=O)C(CCCNC(=N)N)NC(=O)C(CCCNC(=N)N)NC(=O)C(CS)NC(=O)C(CCC(=O)O)NC(=O)C(CCC(=O)O)NC(=O)C(C(C)CC)NC(=O)C(C(C)O)NC(=O)C(CCCCN)NC(=O)C(CC1=CC=CC=C1)NC(=O)C(CCCNC(=N)N)NC(=O)C(CC(=O)N)NC(=O)C(CO)NC(=O)C(CC(=O)N)NC(=O)CNC(=O)CNC(=O)C(CS)NC(=O)CNC(=O)C(CO)NC(=O)C(CC2=CNC3=CC=CC=C32)NC(=O)C(CC(=O)O)NC(=O)C(CC4=CC=CC=C4)NC(=O)C(CCCNC(=N)N)NC(=O)C(CCC(=O)O)NC(=O)C(CS)NC(=O)C(CCC(=O)N)NC(=O)C(CCCCN)NC(=O)C(CCCCN)NC(=O)C(CCCCN)NC(=O)C(CCC(=O)N)NC(=O)C(CC(=O)N)NC(=O)C(CC5=CC=C(C=C5)O)NC(=O)C(CC6=CC=C(C=C6)O)NC(=O)C(CC7=CC=CC=C7)NC(=O)C(C)NC(=O)C8CCCN8C(=O)C(C(C)CC)NC(=O)C(CCCCN)NC(=O)C(CC(=O)O)NC(=O)C(CC9=CC=C(C=C9)O)NC(=O)C(CS)NC(=O)C(CCCNC(=N)N)NC(=O)CNC(=O)C1CCCN1C(=O)C(CC(=O)N)NC(=O)C(CCCNC(=N)N)NC(=O)C(CC1=CN=CN1)NC(=O)C(CC(C)C)NC(=O)C(C(C)CC)NC(=O)C(CS)NC(=O)C(CC(C)C)NC(=O)C(CCCCN)NC(=O)C(CCCNC(=N)N)NC(=O)C(CCCNC(=N)N)NC(=O)C1CCCN1C(=O)C(CCC(=O)O)N PRINT SCANC1=CC(=C(C=C1[N+](=O)[O-])[N+](=O)[O-])Cl FINDN+ MyString.cpp MyString.cpp // TODO: Implement this source file MyString.h // TODO: Implement this header file Rover.cpp #include #include "Rover.h" #include "MyString.h" using std::cout, std::endl; void Rover::print() { cout < savedsmile="">< endl;="" mystring:=""><() }="" void="" rover::read(int="" n)="" {="" cout="">< savedsmile.at(n)="">< endl;="" mystring:="" at()="" }="" void="" rover::clear()="" {="" if="" (!savedsmile.empty())="" {="" mystring:="" empty()="" savedsmile.clear();="" mystring:="" clear()="" }="" }="" void="" rover::join(mystring="" input)="" {="" savedsmile="" +="input;" mystring:="" operator+="()" }="" mystring="" rover::test(mystring="" input)="" {="" mystring="" tester(savedsmile);="" mystring:="" copy="" constructor="" tester="" +="input;" mystring:="" operator+="()" return="" tester;="" mystring:="" destructor="" }="" bool="" rover::find(mystring="" search)="" {="" int="" index="savedSMILE.find(search);" return="" index="">= 0; // MyString: find() } Rover.h #ifndef ROVER_H #define ROVER_H #include "MyString.h" class Rover { private: MyString savedSMILE; // MyString: default constructor public: // constructors Rover() : savedSMILE("") {} // MyString: parameterized constructor (const char* type) Rover(MyString newSMILE) : savedSMILE(newSMILE) {} // MyString: parametered constructor (MyString type), i.e., copy constructor // getters MyString getSMILE() { return savedSMILE; } // setters void setSMILE(MyString SMILE) { savedSMILE = SMILE; } // MyString: operator=(), copy assignment constructor // Rover chemical analysis functions // these are implemented in the Rover.cpp file void print(); void read(int n); void clear(); void join(MyString input); MyString test(MyString input); bool find(MyString search); }; #endif RoverTest.cpp #include #include #include "Rover.h" #include "MyString.h" using std::cin, std::cout, std::endl, std::ifstream, std::istream; // helper function "stoi" to converts MyString to int, works a lot like number slicing in reverse int stoi(const MyString& str, size_t* pos = nullptr, int base = 10) { // just doing base 10 here int result = 0; for (unsigned int i = 0; i < str.size();="" i++)="" {="" mystring:="" size()="" if="" (str.at(i)="">= '0' && str.at(i) <= '9')="" {="" mystring:="" at()="" result="" *="10;" increase="" digit="" (reverse="" of="" number="" slicing)="" result="" +="str.at(i)" -="" 48;="" using="" ascii="" for="" conversion="" }="" }="" return="" result;="" }="" helper="" function="" for="" insertion="" allows="" reading="" from="" input="" stream="" to="" mystring="" istream&="" operator="">>(istream& is, MyString& str) { str.clear(); while (!is.eof()) { char c; is >> std::noskipws >> c; // use the noskipws manipulator if (isspace(c) || is.fail()) break; // if whitespace, can stop adding to string const char* newstr = new char[2] {c, '\0'}; MyString newc = MyString(newstr); // MyString: copy constructor delete[] newstr; str += newc; // MyString: operator+=() } return is; } int main () { // open command file MyString filename; // MyString: default constructor cin >> filename; // operator>> is provided above ifstream commands(filename.data()); // MyString: data() return const char* type (otherwise, have to implement ifstream constructor for MyString type) if (!commands.is_open()) { cout < "unable="" to="" open="" file"="">< endl;="" return="" 1;="" }="" setup="" test="" rover="" rover="" testrover;="" read="" commands="" mystring="" comm;="" mystring="" data;="" while="" (!commands.eof())="" {="" commands="">> comm; if (comm.front() == 'P') { // MyString: front() testRover.print(); continue; } if (comm.front() == 'C') { testRover.clear(); continue; } commands >> data; switch (comm.front()) { case 'S': testRover.setSMILE(data); break; case 'R': testRover.read(stoi(data)); // stoi is provided above break; case 'J': testRover.join(data); break; case 'T': cout < testrover.test(data)="">< endl;="" break;="" case="" 'f':="" cout="">< data="">< "="" ";="" mystring:=""><() if="" (testrover.find(data))="" {="" cout="">< "was="" found"="">< endl;="" }="" else="" {="" cout="">< "was="" not="" found"="">< endl;="" }="" break;="" default:="" continue;="" }="" }="" return="" 0;="" }="" hw:="" mars="" rover="" hw:="" mars="" rover="" overview="" on="" february="" 18,="" 2021,="" we="" celebrated="" the="" landing="" of="" the="" latest="" mars="" rover,="" perseverance.="" the="" perseverance="" rover="" is="" a="" remarkable="" feat="" of="" science="" and="" engineering.="" engineers="" must="" optimize="" every="" aspect="" of="" their="" design="" to="" accommodate="" strict="" requirements="" for="" space="" vehicles.="" in="" fact,="" due="" to="" reliability="" specifications,="" perseverance="" is="" powered="" by="" a="" 20="" year="" old="" processor!="" a="" (hypothetical)="" new="" rover="" for="" this="" assignment,="" assume="" you="" are="" on="" a="" team="" of="" engineers="" working="" on="" a="" sophisticated="" chemical="" composition="" analysis="" system="" for="" a="" new="" mars="" rover.="" this="" rover="" will="" have="" even="" more="" advanced="" automation="" and="" learning="" capabilities="" than="" previous="" ones,="" and="" the="" chemical="" analysis="" tool="" is="" a="" key="" part="" of="" its="" ability="" to="" study="" the="" martian="" surface.="" the="" rover="" uses="" the="" simplified="" molecular-input="" line-entry="" system="" (smiles)="" to="" store="" and="" operate="" on="" chemical="" data.="" smiles="" are="" string="" representations="" of="" 3="" dimensional="" molecular="" structures,="" enabling="" computational="" software="" to="" model="" complex="" structures="" in="" a="" format="" that="" is="" easy="" to="" store="" and="" use.="" your="" team="" discovers="" that="" the="" program="" isn’t="" running="" correctly="" on="" the="" rover,="" and="" you’ve="" identified="" the="" problem="" is="" tied="" to="" memory.="" specifically,="" the="" rover="" doesn’t="" have="" quite="" enough="" memory="" to="" load="" the="" full="" program.="" rather="" than="" remove="" core="" functionality,="" you’ve="" discovered="" that="" just="" removing="" some="" library="" code="" frees="" up="" enough="" resources="" to="" make="" the="" program="" run.="" note="" this="" is="" a="" toy="" problem="" and="" doesn’t="" have="" much="" basis="" in="" reality.="" it’s="" true:="" space="" technology="" is="" heavily="" constrained="" for="" reliability="" purposes="" and="" smiles="" is="" a="" useful="" string-based="" way="" to="" process="" chemical="" data,="" but="" the="" hypothetical="" scenario="" is="" made="" up="" for="" this="" assignment.="" objective="" you="" must="" implement="" a="" custom="" mystring="" object="" that="" will="" mimic="" the="" standard="" c++="" string="" object="" for="" certain="" functions.="" to="" facilitate="" this,="" we="" have="" provided="" a="" sample="" “test”="" rover="" which="" is="" nothing="" more="" than="" some="" simple="" functions="" to="" call="" your="" mystring="" object.="" we="" will="" read="" a="" set="" of="" basic="" commands="" from="" a="" file="" to="" simulate="" the="" chemical="" composition="" tool.="" note="" that="" you="" must="" not="" use="" the="" library="" string="" or="" vector="" classes="" since="" that="" would="" defeat="" the="" purpose="" of="" mystring.="" see="" allowed="" includes="" for="" more="" information.="" by="" implementing="" your="" own="" mystring="" class,="" you="" will:="" ●="" practice="" writing="" classes="" with="" dynamic="" memory="" https://en.wikipedia.org/wiki/perseverance_(rover)="" https://bigthink.com/technology-innovation/perseverance-rover-brain="" https://en.wikipedia.org/wiki/simplified_molecular-input_line-entry_system="" ●="" practice="" operator="" overloading="" ●="" apply="" the="" rule="" of="" three="" steps="" 1.="" download="" the="" starter="" code="" from="" mimir.="" 2.="" read="" the="" provided="" main()="" in="" rovertest.cpp="" and="" the="" simplified="" rover="" operations="" in="" rover.h="" and="" rover.cpp.="" a.="" you="" should="" not="" change="" these="" files.="" b.="" they="" call="" certain="" functions="" on="" your="" mystring="" object,="" testing="" the="" operations="" for="" the="" hypothetical="" chemical="" analysis="" software.="" 3.="" there="" are="" two="" blank="" files:="" mystring.h="" and="" mystring.cpp.="" a.="" you="" will="" need="" to="" implement="" these="" files="" by="" writing="" your="" mystring="" class="" from="" scratch.="" b.="" the="" unit="" tests="" on="" mimir="" can="" help="" provide="" scaffolding="" for="" your="" functions,="" and="" you="" can="" write="" custom="" main="" files="" to="" test="" different="" parts="" of="" your="" mystring="" class.="" 4.="" go="" through="" the="" implementation="" details="" below="" to="" review="" the="" functions="" you="" will="" implement.="" you="" will="" be="" able="" to="" find="" all="" the="" functions="" that="" are="" called="" by="" searching="" for="" these="" comments="" in="" the="" starter="" code:="" mystring:=""> a. Before you can compile, you must write at least the function declarations and function definitions that return some value of the expected type for non-void functions. b. Once you have the basic setup of your class, even though it may be incomplete, you can start using local testing and Mimir to test your code. 5. Repeat the process of implementing, testing, and submitting to refine your code and complete more the MyString class. Implementation Details For this assignment, you will be writing a custom MyString class from scratch. It is based on the C++ string object, so we will be referencing the CPlusPlus.com’s string reference extensively! Note that on some reference pages, there will be multiple versions of C++ listed. You can pick the most recent standard available since we are compiling against C++17. For example, the image below shows options for C++98 and C++11, with version 11 highlighted. https://class.mimir.io/projects/392afa32-cbca-4a33-90ef-3256baa419fb http://www.cplusplus.com/reference/string/string/ General Suggestions ● A good first step is to read the provided test rover files. Inside each file, there is a comment of the form “// MyString: …” which tells which operation will need to be implemented to make that part of the code work. ● When you start writing your class, remember to implement header guards in order to avoid compiler errors tied to repeat includes. ● The following would be a good command line to start compiling. You need to have declarations and at least a definition for each function, even if it doesn’t do anything, before it will compile. g++ -std=c++17 -Wall -Wextra -pedantic-errors -Weffc++ -Wno-unused-parameter -fsanitize=undefined,address RoverTest.cpp Rover.cpp MyString.cpp MyString private members The most important part of your custom MyString object will be its data. Recall that strings are essentially dynamic character arrays that also track their size and capacity. You will want to write your MyString class with private members to hold this information. Because this part is not directly tested, you will need to implement this to a certain extent yourself. If you find yourself struggling with this part, start slowly by reviewing the key concepts you know: How do you define a class named MyString? How can you define private members to hold the size and capacity inside the new class? What about the character array? Remember you’ll need it to be a pointer since you want to dynamically allocate and deallocate the data on the heap based on the string’s size. Also, remember that our string object is essentially a c-string on the inside, just with additional members to track size and capacity and perform some operations. You may want to review the c-string lab or your lecture notes on the subject. The key thing to recall is that the character array ends with a null terminator: ‘\0’ MyString public members You can find comments in the files of which functions and parameters you must implement. Below, we list the functions belonging to the original C++ object that we will require in testing your new MyString object, and these are necessary for the provided runner to work. Note that we are using the name given by CPlusPlus.com at the top next to the function signatures. Furthermore, keep in mind that references to “string” datatype will have to use your “MyString” datatype instead. string reference ● (constructors) ○ default (1) ○ copy (2) ○ from c-string (4) ● (destructor) ● resize: ○ Top one only: void resize (size_t n); ○ This one isn’t tested explicitly but is necessary to support many other operations ● capacity ○ This one isn’t tested explicitly but is used by resize operations. It tracks the current size of the internal array ● size ○ Size is the current number of elements in the array ● length ● data ○ This function returns the internal character array’s reference because it is actually a c-string on the inside, so remember the null terminator ● empty ● front ○ Second one only: const char& front() const; ● at ○ Second one only: const char& at (size_t pos) const; ○ Remember to do bounds checking and throw the exception if out of bounds ● clear ● operator< ● operator= ○ string (1) ● operator+= ○ string (1) ● find ○ string(1) ○ if a start index isn’t passed, ●="" operator="○" string="" (1)="" ●="" operator+="○" string="" (1)="" ●="" find="" ○="" string(1)="" ○="" if="" a="" start="" index="" isn’t="">
Answered 174 days AfterJul 29, 2021

Answer To: commands1.txt SCANC1=C(C(C=C(C1O)Cl)O)Cl JOIN[NH4+] PRINT CLEAR JOINN+(C1=CC) PRINT...

Karthi answered on Jan 19 2022
123 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here