C++ simple program help String Data -
thanks helping me in advance! used java , c# c++ different. trying part b of lab: http://cs.binghamton.edu/~sgreene/cs240-2010f/labs/lab2.html
is idea assigned in part b? dont know missing in header file deals indef endif, etc. did research , dont seem miss anything. , lastly, lab assignment mean when says: "in [] operator, index should checked confirm between 0 , 9. if not, string "undefined" should returned instead." thanks
ok here updated files
#include "tenstrings.h" using namespace std; //default constructor tenstrings::tenstrings() { public: tenstrings str[10]; str[0] = "string 1"; str[1] = "string 2"; str[2] = "string 3"; str[3] = "string 4"; str[4] = "string 5"; str[5] = "string 6"; str[6] = "string 7"; str[7] = "string 8"; str[8] = "string 9"; str[9] = "string 10"; } ;
main.cpp --------------------------*/
#include "tenstrings.h" #include <iostream> int main() { tenstrings varten; std::cout << str[2] << std::endl; return 0; }
also line missing in header file: #include ?
i notice assignment carries warning:
this individual assignment - may not work in groups. not write or dictate code else, , not use code else. if break rule, may fail entire class.
hence provide guidance, not code.
first dont know create new data strings, whether should in header class or tenstrings.cpp?
the assignment says:
implement tenstrings class such acts array of 10 constant-data strings. start basic [] operator, , constructor.
the word "implement" key. until know inline function definitions (which i'm guessing haven't gotten yet), implementation needs in 1 of cpp
files (in case, tenstrings.cpp
.)
should create array of empty strings? or array of string1, string2, string3, etc?
the assignment says:
in constructor, 10 strings should set "first string", "second string", etc....
in other words, constructor tenstring class should make first string (i.e., @ index [0]
) have exact value "first string"
; , on through tenth string (at index [9]
) having exact value "tenth string"
. apparently, intent able change these assignments through []
operator, write part of tenstring class.
i hope helps. (i think i've interpreted assignment correctly, can't guarantee that.)
oh, , way, there's no need line:
#include <string>
since assignment says not use string class.
edit: also, header file seems missing line @ beginning. missing line related #ifndef
/ #define
/ #endif
protection that's mentioned in assignment.
Comments
Post a Comment