Question

In: Computer Science

UPDATE: Whole Code How do I fix this Bold part "!= Null" ? its showing me...

UPDATE: Whole Code

How do I fix this Bold part "!= Null" ? its showing me Error? please Help

#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<stdlib.h>
#include<sstream>


using namespace std;

int main(){

string list[1000];
cout << "! Opening data file... ./Data.CS.SFSU.txt\n";
ifstream fin("Data.CS.SFSU.txt");
if(fin.fail()){
cout << "Error opening file\n";
return 0;
}
cout << "! Loading data...\n";
int count = 0;
while(getline(fin,list[count])!=NULL){
//cout << "--------------------\n";
count++;
}

cout << "! Loading completed...\n";
fin.close();
cout << "! Closing data file... ./Data.CS.SFSU1.txt\n";
cout << "-----DICTIONARY 340 C++-----\n";
while(true){
cout << "Search:";
string line;
getline(cin,line);
cout << "|" << endl;
stringstream ss(line);
  
string word1, word2, word3;
ss >> word1 >> word2;
if (ss >> word3 || (word2 != "noun" && word2 != "adjective" && word2 != "verb")){
cout << "Please enter a search key (and a part of speech)\n";
}
else {
for (int i = 0; i<word1.length(); i++){
word1[i] = tolower(word1[i]);
}
int found = 0;
cout << count << endl;
  
for (int i = 0; i< count; i++){
char line2[200];
strcpy(line2, list[i].c_str());
char *ch = strtok(line2,"|");
//cout << ch << endl;
while (ch != NULL){
//cout << ch << endl;
//cout << ch1 << " " << endl;
if (strcmp(ch,(char *)word1.c_str()) == 0){
ch = strtok(NULL,"|");

char line[100];
strcpy(line, ch);
char *ch1 = strtok(line," ");
//cout << line << endl;
if (strcmp(ch1,word2.c_str()) == 0){
ch1 = strtok(NULL," ");
ch1 = strtok(NULL," ");
string s ="";
while (ch1 != NULL){
s = s + ch1 + " ";
ch1 = strtok(NULL," ");
}
cout << word1 << "[" << word2 << "] :" << s << endl;
found = 1;
break;
}
}
ch = strtok(NULL,"|");
}
if (found == 1)
break;
}
if (found == 0)
cout << "Not found\n";
}
cout << "|" << endl;
  
}
return 0;
}

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE

#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<stdlib.h>
#include<sstream>


using namespace std;

int main(){

string list[1000];
cout << "! Opening data file... ./Data.CS.SFSU.txt\n";
ifstream fin("Data.CS.SFSU.txt");
if(fin.fail()){
cout << "Error opening file\n";
return 0;
}
cout << "! Loading data...\n";
int count = 0;
while(getline(fin,list[count])){
//cout << "--------------------\n";
count++;
}

cout << "! Loading completed...\n";
fin.close();
cout << "! Closing data file... ./Data.CS.SFSU1.txt\n";
cout << "-----DICTIONARY 340 C++-----\n";
while(true){
cout << "Search:";
string line;
getline(cin,line);
cout << "|" << endl;
stringstream ss(line);
  
string word1, word2, word3;
ss >> word1 >> word2;
if (ss >> word3 || (word2 != "noun" && word2 != "adjective" && word2 != "verb")){
cout << "Please enter a search key (and a part of speech)\n";
}
else {
for (int i = 0; i<word1.length(); i++){
word1[i] = tolower(word1[i]);
}
int found = 0;
cout << count << endl;
  
for (int i = 0; i< count; i++){
char line2[200];
strcpy(line2, list[i].c_str());
char *ch = strtok(line2,"|");
//cout << ch << endl;
while (ch != NULL){
//cout << ch << endl;
//cout << ch1 << " " << endl;
if (strcmp(ch,(char *)word1.c_str()) == 0){
ch = strtok(NULL,"|");

char line[100];
strcpy(line, ch);
char *ch1 = strtok(line," ");
//cout << line << endl;
if (strcmp(ch1,word2.c_str()) == 0){
ch1 = strtok(NULL," ");
ch1 = strtok(NULL," ");
string s ="";
while (ch1 != NULL){
s = s + ch1 + " ";
ch1 = strtok(NULL," ");
}
cout << word1 << "[" << word2 << "] :" << s << endl;
found = 1;
break;
}
}
ch = strtok(NULL,"|");
}
if (found == 1)
break;
}
if (found == 0)
cout << "Not found\n";
}
cout << "|" << endl;
  
}
return 0;
}


Related Solutions

Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
Can someone tell me how to fix warning msg in my code of C ++? I...
Can someone tell me how to fix warning msg in my code of C ++? I got run-time error for this question please help me asap! Errors are: In function 'void bfs(int, int)': warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int j = 0; j < adj[pppp].size(); j++){ ^ In function 'int main()': warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %d %d %d", &a, &q, &c, &N, &m); ^...
JAVA: How do I fix the last "if" statement in my code so that outputs the...
JAVA: How do I fix the last "if" statement in my code so that outputs the SECOND HIGHEST/MAXIMUM GPA out of the given classes? public class app { private static Object minStudent; private static Object maxStudent; public static void main(String args[ ]) { student st1 = new student("Rebecca", "Collins", 22, 3.3); student st2 = new student("Alex", "White", 19, 2.8); student st3 = new student("Jordan", "Anderson", 22, 3.1); student[] studentArray; studentArray = new student[3]; studentArray[0] = st1; studentArray[1] = st2; studentArray[2]...
I need to fix this code, and could you please tell me what was the problem...
I need to fix this code, and could you please tell me what was the problem options 1 and 9 don't work #include <stdio.h> #include <time.h> #include <stdlib.h> // generate a random integer between lower and upper values int GenerateRandomInt(int lower, int upper){     int num =(rand()% (upper - lower+1))+lower;     return num; } // use random numbers to set the values of the matrix void InitializeMatrix(int row, int column, int dimension, int mat[][dimension]){     for(int i =0; i<row; i++){...
Can you fix to me this code plz I just want to print this method as...
Can you fix to me this code plz I just want to print this method as the reverse. the problem is not printing reverse. public void printBackward() {               Node curr = head;        Node prev = null;        Node next = null;               System.out.print("\nthe backward of the linkedlist is: ");               while(curr != null) {            next = curr.next;            curr.next = prev;   ...
Can anyone fix this code? The code isn't rounding the answer to the nearest whole number...
Can anyone fix this code? The code isn't rounding the answer to the nearest whole number like 2.345 should be 2 and 2.546 should be 3 but the round() function isn't working as expected. The round() function is rounding 2.546 to 2 which is incorrect since 4 and below should be rounded to 2 and 5 and above should be rounded to 3. Here is the code: #importing xlwt library to write into xls import xlwt from xlwt import Workbook...
I already have the code of this program, I just want to know how to fix...
I already have the code of this program, I just want to know how to fix the code to Implement the 5th function (System.nanotime() and System.currentTimeMillis() methods) What Code does: Introduction Searching is a fundamental operation of computer applications and can be performed using either the inefficient linear search algorithm with a time complexity of O (n) or by using the more efficient binary search algorithm with a time complexity of O (log n). Task Requirements In this lab, you...
can you please look at the following code and fix it for me so that it...
can you please look at the following code and fix it for me so that it does not have any syntax errors. also can you tell me what was fixed /** * Driver program to demonstrate calling methods of Client class. * * @author Doyt Perry/Tina Comston * @version Fall 2019 */ public class ClientDemo { public static void main() { /** * main method - makes this an executable program. */ // create a client with placeholder values System.out.println("Client...
I do not know how to answer part b. Can you show me how to conduct...
I do not know how to answer part b. Can you show me how to conduct a hypothesis test for this problem? As I know the answer for part a is 0.4 Let X be the weight of flour (in g) contained in a 1kg bag of flour made by a certain company and assume X~U(980,1030). a) What is the probability that the bag of flour has less than 1kg of flour in it? b) The owner of this factory...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT