Well I didn't write code. I hate to write code on paper.
I wrote what need to be done.
//Iterate through the vector
//if( iter == index)
// return element_type
something similar to this.
User Profile
Collapse
-
data structure question
Hello,
Can someone help me with the answer for this question. This is an exam I did a couple of week back and I don't understand why I got it wrong. AND I don't understand the answer the instructor gave me either.
QUESTION
Suppose the following partial definition for a vector class. Fill the method indicated below so that it functions as described in the comments. You should write your answer in C++ or... -
-
map<string,string> error
I need help with inserting a string for both key and value to a map.
Code:while(!myHuffFile.eof()){ string word, code; int freq; myHuffFile >> word >> freq >> code; if(word == ""){ break; }else{ _fileMap.insert(pair<string,string>(word,code)); _freqMap.insert(pair<string,int>(word,freq));
-
-
-
stl/map and string question
I have string and a map<string,int>
i need to iterate through the map and find string[i] and replace the int with the string.
eg: if map contains
hello 6
world 4
its 3
me 60
if the string is "its me hello world world hello"
output should be "3 60 6 4 4 6"
Code:for(int i = 0 ; i < str.length() ; i++){
-
Code:bool caseFlag = false; while(!caseFlag){ switch (option){ case 'y' : remove("file.txt"); caseFlag = true; break; case 'n' : caseFlag = true; exit(0); default : cout << "Invalid entry" << endl; cin >> option; caseFlag = false; } }
Leave a comment:
-
ok i used a boolean and a while loop and fixed it but shouldnt the case statement take care of any invaild input???Leave a comment:
-
switch case statements question
how do i make sure that the switch case doesnt ternimate the program if the entry is invalid.
in my program, if user input is y, removes the file. if user input is n, exits program, if user input is anything else prints out error message prompts for user input again and if that is a invalid input it terminates program. i dont want it to terminate the program. until the correct input is entered, it needs to prompt the user.
... -
Incorrect output file: c++ (i/o) question
I encode a text file using a huffman tree. Which print out to the screen and and output to a file. File only contains the last line that prints to the console.
Code:void traverse(string code = "") const { string outputFile = "huffman.txt"; ofstream outfile(outputFile.c_str()); if (child0 !=NULL) { static_cast<huffman_item<dtype> >( *child0).traverse(code
-
I figured it out! But couldn't have done it without your help mate!
instead of => tempVec.push_ba ck(spaceLine.su bstr(x, x+1));
I did => tempVec.push_ba ck(spaceLine.su bstr(x, 1));
When its x+1 the first substring will be an empty string with size 1 an second will be empty string with size 2 and so on... Because we loop through the string.
tempVec.push_ba ck(spaceLine.su bstr(x, 1)); does what...Leave a comment:
-
thanks! didn't know that ASCII values were different! when you say platform is the OS you talking or compiler?
If OS, my programs worked on both linux and windows, and if compiler my program compiles on VS and g++....Leave a comment:
-
-
I haven't done this in C but have done this in C++, java and C#.
psuedo code:
string someFunction(st ring string){
string str;
for(int i = 0 ; i<string.size( ) ; i++) {//loop through the main string passed in character by character
char j = string[i];
if(j>=65 && j<=90 || j>=97 && j<=122 || j == 32 || j>=48 && j<=57){ //these numbers are ascii...Leave a comment:
-
i did what you said this is the output i get:
vector "hello"
vector "world"
vector "apple"
vector "cat"
vector "hello"
vector "world"
vector " "
vector " "
vector " "
vector " "
vector " "
vector " "
vector " "...Leave a comment:
-
This is not my assignment mate... yeah this is how my instructor wants... basically I making a word frequency map to be encoded using a huffman code.
project is read in a very large text file, and encode it....Leave a comment:
-
-
adding # of spaces in string to map
hello,
This is my 1st post here!
*welcome drjay*
Thanks! I look answering questions and getting answers to other!
Now that we got that out of the way. I'm trying to read in a string and add the unique words in the string to a map. Eg:
string = "hello world! hello world... I'm a live"
map<string,int>
hello 2
wold 2
...
No activity results to display
Show More
Leave a comment: