Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with some errors when trying to build a program. 1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ 1>assignment1searchandsort.cpp 1>c:userszosource eposconsoleapplication1consoleapplication1assignment1searchandsort.cpp(18): error

I need help with some errors when trying to build a program.

1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ 1>assignment1searchandsort.cpp 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(18): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(19): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(19): error C3861: 'setw': identifier not found 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(21): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(21): error C3861: 'setw': identifier not found 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(23): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(23): error C2563: mismatch in formal parameter list 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(23): error C2568: '<<': unable to resolve function overload 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(23): note: could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(89): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(90): error C2065: 'cin': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(92): error C2079: 'infile' uses undefined class 'std::basic_ifstream>' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(92): error C2440: 'initializing': cannot convert from 'char [50]' to 'int' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(92): note: There is no context in which this conversion is possible 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(93): error C2228: left of '.is_open' must have class/struct/union 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(93): note: type is 'int' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(95): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(103): error C2672: 'getline': no matching overloaded function found 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(103): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)': could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'int' 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.11.25503\include\string(155): note: see declaration of 'std::getline' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(103): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)': expects 3 arguments - 2 provided 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.11.25503\include\string(144): note: see declaration of 'std::getline' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(103): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)': could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &&' from 'int' 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.11.25503\include\string(124): note: see declaration of 'std::getline' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(103): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)': expects 3 arguments - 2 provided 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.11.25503\include\string(71): note: see declaration of 'std::getline' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(105): error C2228: left of '.close' must have class/struct/union 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(105): note: type is 'int' 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(111): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(112): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(113): error C2065: 'cin': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(128): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(129): error C2065: 'cin': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(133): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(134): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(135): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(136): error C2065: 'cin': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(142): error C2065: 'cout': undeclared identifier 1>c:\users\zo\source epos\consoleapplication1\consoleapplication1\assignment1searchandsort.cpp(144): error C2065: 'cout': undeclared identifier 1>Done building project "ConsoleApplication1.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is the code:

#include

#include

#include

#include "stdafx.h"

#include

using namespace std;

void display(string message, string words[], int n);

void selectionSort(string words[], int n);

void bubbleSort(string words[], int n);

int binarySearch(string words[], int n, string search);

int linearSearch(string words[], int n, string search);

void display(string message, string words[], int n)

{

cout << message << endl;

cout << left << setw(12) << "Index" << setw(30) << "Word" << endl;

for (int i = 0; i < n; i++)

cout << left << setw(12) << i << setw(30) << words[i] << endl;

cout << endl << endl;

}

void selectionSort(string words[], int n)

{

int minIdx;

string temp;

for (int i = 0; i < n; i++)

{

for (int j = i + 1; j < n; j++)

{

if (words[j] < words[minIdx])

minIdx = j;

}

if (i != minIdx) //swap?

{

temp = words[i];

words[i] = words[minIdx];

words[minIdx] = temp;

}

}

}

void bubbleSort(string words[], int n)

{

for (int i = 0; i < n - 1; i++)

{

for (int j = 0; j < n - i - 1; j++)

{

if (words[j] > words[j + 1]) //compare 2 consecutive locations and swap if needed

{

string temp = words[j];

words[j] = words[j + 1];

words[j + 1] = temp;

}

}

}

}

int binarySearch(string words[], int n, string search)

{

int low = 0, high = n - 1;

int mid;

while (low <= high)

{

mid = (low + high) / 2;

if (words[mid] == search)

return mid;

else if (search < words[mid])

high = mid - 1;

else

low = mid + 1;

}

return -1;//when not found

}

int linearSearch(string words[], int n, string search)

{

for (int i = 0; i < n; i++)

{

if (words[i] == search)

return i;

}

return -1; //when not found

}

int main()

{

char filename[50];

cout << "Enter input filename: ";

cin >> filename;

ifstream infile(filename);

if (!infile.is_open())

{

cout << "Error, could not open: " << filename << endl;

return 1;

}

//put the strings into the array

string words[50];

int n = 0;

while (getline(infile, words[n]))

n++;

infile.close();

display("Words before sorting", words, n);

int choice;

cout << "You may enter 1 to selection sort, or 2 to bubble sort." << endl;

cout << "Enter your choice: ";

cin >> choice;

if (choice == 1)

selectionSort(words, n);

if (choice == 2)

bubbleSort(words, n);

display("Words after sorting", words, n);

string search = "";

int index;

while (search != "stop")

{

cout << "Enter a word to search(type stop to stop): ";

cin >> search;

if (search != "stop")

{

cout << "1. Linear search" << endl;

cout << "2. Binary search" << endl;

cout << "Enter your choice: ";

cin >> choice;

if (choice == 1)

index = linearSearch(words, n, search);

else

index = binarySearch(words, n, search);

if (index == -1)

cout << search << " NOT found" << endl << endl;

else

cout << search << " found at index " << index << endl << endl;

}

}

}

It will compile fine on other compilers like https://www.onlinegdb.com/online_c++_compiler.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions