Question: Unix/Linux Assignment 9 Please Help! 1.Create a directory ~/UnixCourse/compileAsst 2.Copy the files from ~cs252/Assignments/guess/ into your newly created directory. 3.Compile the code, capturing the error
Unix/Linux Assignment 9
Please Help!
1.Create a directory ~/UnixCourse/compileAsst
2.Copy the files from ~cs252/Assignments/guess/ into your newly created directory.
3.Compile the code, capturing the error messages by any of the techniques covered in this modules lesson.
4.
Open a separate ssh session in a second window. In there, give the command:
~cs252/bin/compileAsst
This will ask you some questions about the errors that you observed.
Eventually, it will instruct you to fix the errors and to recompile the code.
5.In your first window, use an editor to fix the errors in the code.
Each error can be fixed by a change of no more than 2 characters on a a single line. If you find yourself doing anything more complicated, stop!
Then recompile to produce an executable file named program.
1. In your second window, answer any remaining questions.
~I have done almost all the steps correcting the code, what I am stuck on is compiling the files given below and producing a new executable file called "program".~
~cs252/Assignments/guess/ Includes these files:
~cs252/Assignments/guess/guess.cpp
#include
#include
#include "yesno.h"
using namespace std;
//
// Try to guess a number beween low and high (exclusive)
// by asking a series of "Is it bigger than X?" questions.
// Return true if able to guess it. Return false and complain
// if person's responses are inconsistent.
bool doGuesses (int low, int high)
{
if (low >= high)
{
cout << "Hey, no cheating! There is no number that is ";
return false;
}
else if (high == low + 2)
{
cout << "I'm guessing that your number is " << low+1 << endl;
cout << "Is that right? " << flush;
string response;
getline(cin, response);
if (yesNo(response))
{
cout << " Hooray! (Oops. Sorry - I don't mean to gloat.)" << endl;
return true;
}
else
{
cout << "Hey, no cheating! There is no number other than "
<< low+1 << " that is ";
return false;
}
}
else
{
int mid = (low + high) / 2;
cout << "Is your number bigger than " << mid << "? " << flush;
string response;
getline(cin, response);
if (yesNo(response))
{
if (doGuesses(mid,high))
return true;
else
{
cout << " bigger than " << mid << ", ";
return false;
}
}
else
{
if (doGuesses(low,mid+1))
return true;
else
{
cout << " smaller than " << mid+1 << ", ";
return false;
}
}
}
}
int main()
{
cout << "Think of an integer between 1 and 1000. I will try to guess it."
<< endl;
bool result = doGuesses(0, 1001);
if (!result) {
cout << " and is between 1 and 1000." << endl;
cout << " I demand a rematch!" << endl;
}
return 0;
}
~cs252/Assignments/guess/yesno.cpp
#include "yesno.h"
using namespace std;
string toUpperCase(string x);
// Return true if response is "yes", "y", or any upper/lowercase
// variant of those two strings.
bool yesNo(string response)
{
response = toUpperCase(response);
if (response.length() == 1)
{
return (response == "Y");
}
else if (response.length() == 3)
{
return (response[0] == 'Y')
&& (response[1] == 'E')
&& (response[2] == 'S');
}
else
return false;
}
// Convert any upper-case characters in a string to lower-case
string toLowerCase(string x)
{
for (int i = 0; i < x.length(); ++i)
{
if (x[i] >= 'A' && x[i] <= 'Z')
{
x[i] = x[i] + 'a' - 'A';
}
}
return x;
}
// Convert any lower-case characters in a string to upper-case
string toUpperCase(string x)
{
for (int i = 0; i < x.length(); ++i)
{
if (x[i] >= 'a' && x[i] <= 'z')
{
x[i] = x[i] + 'A' - 'a';
}
}
return x;
}
~cs252/Assignments/guess/yesno.h
#ifndef YESNO_H_INCLUDED #define YESNO_H_INCLUDED
#include
// Return true if response is "yes", "y", or any upper/lowercase // variant of those two strings. bool yesNo (std::string response);
#endif // YESNO_H_INCLUDED
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
