| ElizN (3) | |
|
Hi! We are doing a team project. My part is to write the function for changing a string of items to separated items and place them in the vector. Also, to write the function for taking them from the vector and changing them back into a string. I am down to 12 errors, but can't seem to get any further. My teammate wants to use a tokenizer, but I couldn't get it to work and tried using an iterator instead. Most of my errors are due to the verbiage in the iterator not being recognized. Can you help? Heres my code: item.h: #pragma once #ifndef item_h #define item_h #include <string> using namespace std; class item { private: public: string ItNum; string ItName; string WhlslPrice; string NumHand; string MaxNum; string VendorName; string ReOrderNum; string RetPrice; string DeptName; //constructor item(); item(string, string, string, string, string, string, string, string, string); //default constructor //accessor for item number void setItNum(string); string getItNum(); //accessor for item name void setItName(string); string getItName(); //accessor for wholesale price void setWhlslPrice(string); string getWhlslPrice(); //accessor for Num on Hand void setNumHand(string); string getNumHand(); //accessor for Max Num void setMaxNum(string); string getMaxNum(); //accessor for vendor name void setVendorName(string); string getVendorName(); //accessor for reOrderNum void setReOrderNum(string); string getReOrderNum(); //accessor for retail price void setRetPrice(string); string getRetPrice(); //accessor for dept void setDeptName(string); string getDeptName(); };//end class - item #endif *************************** item.cpp #include "StdAfx.h" #include "item.h" #include <string> #include <cstdlib> using namespace std; //default InvData constructor string item(); void item(string ItNumValue, string ItNameValue, string WhlslPriceValue, string NumHandValue, string MaxNumValue, string VendorNameValue, string ReOrderNumValue, string RetPriceValue, string DeptNameValue) { string ItNum (ItNumValue); string ItName (ItNameValue); string WhlslPrice(WhlslPriceValue); string NumHand (NumHandValue); string MaxNum (MaxNumValue); string VendorName (VendorNameValue); string ReOrderNum (ReOrderNumValue); string RetPrice (RetPriceValue); string DeptName (DeptNameValue); } //end item constructor //get item number string getItNum(string ItNumValue) { string ItNum = ItNumValue; return ItNum; }//end function getitNum //set size for item number up to 4 chars void setItNum(string ItNum) { string itNum = ItNum; if (itNum.size() >= 5) { itNum.resize(4); } }//end function setitNum //get item name string getItName(string ItNameValue) { string ItName = ItNameValue; return ItName; }//end function getItName //set size for item name up to 12 chars void setItName(string ItName) { string itName = ItName; if (itName.size() >= 13) { itName.resize(12); } }//end function setitName //get wholesale price string getWhlslPrice(string WhlslPriceValue) { string WhlslPrice = WhlslPriceValue; return WhlslPrice; }//end function getwhlslPrice //set size for wholesale price up to 6 chars void setWhlslPrice(string WhlslPrice) { string whlslPrice = WhlslPrice; if (whlslPrice.size() >= 7) { whlslPrice.resize(6); } }//end function setwhlslPrice //get number on hand string getNumHand(string NumHandValue) { string NumHand = NumHandValue; return NumHand; }//end function getnumHand //set size for number on hand up to 4 chars void setNumHand(string NumHand) { string numHand = NumHand; if (numHand.size() >= 5) { numHand.resize(4); } }//end function setnumHand //get max number string getMaxNum(string MaxNumValue) { string MaxNum = MaxNumValue; return MaxNum; }//end function getmaxNum //set size for max number up to 4 chars void setMaxNum(string MaxNum) { string maxNum = MaxNum; if (maxNum.size() >= 5) { maxNum.resize(4); } }//end function setmaxNum //get vendor name string getVendorName(string VendorNameValue) { string VendorName = VendorNameValue; return VendorName; }//end function getvendorName //set size for vendor name up to 16 chars void setVendorName(string VendorName) { string vendorName = VendorName; if (vendorName.size() >= 17) { vendorName.resize(16); } }//end function setvendorName //get reorder number string getReOrderNum(string ReOrderNumValue) { string ReOrderNum = ReOrderNumValue; return ReOrderNum; }//end function getreOrderNum //set size for reOrder number up to 3 chars void setReOrderNum(string ReOrderNum) { string reOrderNum = ReOrderNum; if (reOrderNum.size() >= 4) { reOrderNum.resize(3); } }//end function setreOrderNum //get retail price string getRetPrice(string RetPriceValue) { string RetPrice = RetPriceValue; return RetPrice; }//end function getretPrice //set size for retail price up to 6 chars void setRetPrice(string RetPrice) { string retPrice = RetPrice; if (retPrice.size() >= 7) { retPrice.resize(6); } }//end function retPrice //get deptName string getDeptName(string DeptNameValue) { string DeptName = DeptNameValue; return DeptName; }//end function getdeptName //set size for dept name up to 12 chars void setDeptName(string DeptName) { string deptName = DeptName; if (deptName.size() >= 13) { deptName.resize(12); } }//end function setdeptName *********************** Main Project file: #include "stdafx.h" #include "item.h" #include <vector> using namespace std; using namespace System; int main(array<System::String ^> ^args) { /****** WHEN THIS BUILDS WITHOUT ERROR SEND IT BACK TO BE TESTED *******/ Console::WriteLine(L"Hello World"); return 0; } /*Elizabeth ********************V stringsToItems function V************* DATE */ //returns a vector<item> and takes in a vector<string> //converts params to proper format before calling the constructor passing in the formated params to create items. //pushes newly created items onto vector before returning vector<string> stringsToItems(vector<string> ) { //split strings into parts vector<string> myChangingArray; //************************************* //char str[] = stringIn; //char * pkl; //tokenizer doesn't work, trying iterator instead /* //get strings from vector items for(int x = 0; x < myChangingArray.size(); x++) { //tokenizes string into separate items pkl = strtok(myChangingArray[x], " "); //use for space separate format while (pkl != NULL) { myChangingArray.push_back(pkl); pkl = strtok(NULL, " "); }*/ //************************************* //create new variables string itNum = myChangingArray[0]; string itName = myChangingArray[1]; string whlslPrice = myChangingArray[2]; string numHand = myChangingArray[3]; string maxNum = myChangingArray[4]; string vendorName = myChangingArray[5]; string reOrderNum = myChangingArray[6]; string retPrice = myChangingArray[7]; string deptName = myChangingArray[8]; //create new inventory items from variables item myItem = new item(itNum, itName, whlslPrice, numHand, maxNum, vendorName, reOrderNum, retPrice, deptName); vector <string>::iterator stringsToItems; for (stringsToItems = myItem.begin();stringsToItems !=myItem.end();++stringsToItems) { stringsToItems.push_back(myItem);//adding the inventory items to the vector } //start vector over in new iterator vector stringsToItems = myItem.begin(); //Cycle forward in vector ++stringsToItems; ++stringsToItems; //Insert new value in iterator vector myItem.insert(stringsToItems); return stringsToItems;//return the vector of items } } //function for changing items to string of items vector<string> itemsToStrings(stringsToItems) { vector<string>stringsToItems; } | |
|
|
|
| Stewbond (1673) | |||
That's a lot of code to read without tags, but from your description, is this what you are looking for?
| |||
|
Last edited on
|
|||