[Zakariya Ahmad]

[Zakariya Ahmad]

Current University of Southern California student working towards a baccalaureate in Cognitive Science

[Scribbler Robot-HW6]

Homework 6 Project Design 1) I would like to teach about the computer science concept of control structures. Within computer science, specifically the use of if/else statements, for loops and switch statements and their important roles in the use of programs.

2) My program will engage the user by having the scribbler robot first draw a circle while it is timed. After the circle is drawn, the user will be told how long it took the robot to draw the circle. The user will be asked if they would like to challenge the robot’s time by controlling the robot via mouse.

3) I am going to create a function for the menu, to allow the user to input their choice of challenging the robot or not. I will also create functions for the mouse control of the robot, the circle drawing the robot will do on it’s own after the user inputs their name, an evaluation function (which will include a graphing function), and input/output functions.

4) I will evaluate the user interaction with my program by recording the user’s data, such as time to draw circle and record it along side the robot’s score. I will also ask the user how much fun they had on a scale of 1-5 and record that alongside the time data. Each of these three will be recorded in their own respective vectors. Which will then be graphed using graphwin.

5) The program will receive user input through cin, whenever they are asked a question and also the user input will be taken from the mouse joystick, depending on where the user clicks on the screen the robot will move in that direction.

6) I will generate an evaluation report based upon the user’s answers to my survey. A high rating (5) will be the best score and a (1) would be the worse. The higher the rating the higher the respective circle for that rating will pop up. I will also graph the user’s time as circles based upon size.

YOUTUBE LINKS: http://www.youtube.com/watch?v=JuRtLzryeco&feature=youtu.be

http://www.youtube.com/watch?v=xPtyS_86Kbk&feature=youtu.be

[Homework 6 Code]

#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;

class io
{
public:
void menu(string);
void input(double, double, double, vector, vector, vector);
void circle(double);
void output(double, double, double);
void enjoy(double);
void joystick(time_t);
private:

int counter;
double like;
double seconds;
double robSeconds;

vector rating;
vector userTime;
vector robTime;


};


void menu(string &name)
{
cout<< "What is your name?"< cin>>name;
cout<< "The robot is going to draw a circle, let's see how fast it can do it."<
}

void circle(double &robSeconds)
{
time_t robTime;
time_t robEndTime;

time(&robTime);

robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);
robot.motors(0.7,-0.1);

robot.motors(0,0);
wait(2);


time(&robEndTime);

robSeconds = robEndTime-robTime;
}
void input(double &seconds, double &robSeconds, double &like, vector &rating, vector &userTime, vector &robTime, int &counter)
{
double sec;
double robSec;
double rate;
string line;
string tempLine;
string tempLine2;
int pos;
int endPos;
int endPos1;
int endPos2;
int endPos3;
ifstream inFile ("evaluation.txt");
if (inFile.is_open()) //confirming the file is open
{
while(!inFile.eof())
{


while(getline(inFile, line))
{
istringstream strStream(line);
strStream >> robSec;
strStream >> sec;
strStream >> rate;

robTime.push_back(robSec);
userTime.push_back(sec);
rating.push_back(rate);

counter++;
}
}
inFile.close();
}
robTime.push_back(robSeconds);
userTime.push_back(seconds);
rating.push_back(like);
}

void output(vector &rating, vector &userTime, vector &robTime, int &counter)
{
counter = counter +1;
ofstream outFile;
outFile.open("evaluation.txt");
vector ::iterator j=robTime.begin(); j!=robTime.end();
vector ::iterator k=userTime.begin(); k!=userTime.end();
for(vector ::iterator l=rating.begin(); l!=rating.end(); l++)
{

outFile<< *j<< " "<< *k<< " "<< *l<< endl;
j++;
k++;
}
}

void enjoy(double &like)
{
cout<< "On a scale of 1-5 how much did you like this demo"<< endl;
cin>>like;
cout<< endl;
}

Color setColor(int c, int z, int b)
{

int red = c;
int green = z;
int blue = b;
return color_rgb(red, green,blue);
}


Color makeColor()
{

int red = rand()%256;
int green = rand()%256;
int blue = rand()%256;
return color_rgb(red, green,blue);
}

void evaluation(vector &rating, vector &userTime, vector &robTime)
{
const int width=900;
const int height=900;



GraphWin canvas("eval_visualization",width,height);
//creates a canvas of specific size
canvas.setBackground("white");
//sets the background to white
int a =100;
int b =700;

vector ::iterator j=robTime.begin(); j!=robTime.end();
vector ::iterator k=userTime.begin(); k!=userTime.end();
for(vector ::iterator l=rating.begin(); l!=rating.end(); l++)
{
int p = rand()%width;
int h = rand()%height;
int q = rand()%width;
int r = rand()%height;
int t = rand()%width;
int y = rand()%height;
int n = (*l*5);
int o = (*k*5);
int b = (*l*5);
Circle f(Point(p, h), n);
f.setFill(setColor(255, 0, 0));
f.draw(canvas);

Text x(Point(p,h), "Rating");
x.setSize(25);
x.draw(canvas);

Circle e(Point(q, r), o);
e.setFill(makeColor());
e.draw(canvas);

Text w(Point(q, r), "User Time");
w.setSize(25);
w.draw(canvas);

Circle a(Point(t, y), b);
a.setFill(setColor(255, 0, 255));
a.draw(canvas);

Text m(Point(t, y), "Robot Time");
m.setSize(25);
m.draw(canvas);

j++;
k++;
}
canvas.saveImage("eval_visualization.jpg");
canvas.waitWinClosed();
}

void joystick(time_t &timer)
{
robot.setForwardness("fluke-forward");

GraphWin win("Joystick", 500, 500);


Circle cir(Point(250,250), 250);
win.setBackground("blue");
cir.setWidth(3);
cir.draw(win);
cir.setFill(setColor(255,255,0));


Point dir;
Point m;
Point center(250,250);
Line l(center,center);
int button=0;

cout<< "BEGIN!"<< endl;
time(&timer);
while(!win.isClosed())
{



m = win.getCurrentMouse(button);

if (m.getX() >= 0 && m.getY() >= 0 && button)
{
dir = center - m;

robot.move(dir.getY()/250.0,dir.getX()/250.0);

l.undraw();
l = Line(center, m);
l.setWidth(3);
l.draw(win);
}

else
{
l.undraw();
robot.move(0,0);

}
wait(0.05);
}
}

int main ()
{
time_t timer;
time_t endTimer;

string name;
double seconds;
double robSeconds;
int counter;
char choice;

vector rating;
vector userTime;
vector robTime;

char ready;
char tryRob;

char finish = 'a';

connect();
robot.beep(0.2,990);


menu(name);

circle(robSeconds);



cout<<"The robot was able to draw a circle in "<
cout<<"Do you think you could draw a circle faster if you controlled the robot? y/n"< cin >> tryRob;
cout<
if(tryRob = 'y')
{
cout << "When you are ready to try to control the robot Press a, press b if you're not ready." << endl;
cin >> ready;

if (ready = 'a')
{
joystick(timer);


time(&endTimer);
}

else
{
cout <<"You're not ready. Okay maybe next time."<< endl;
}

seconds = endTimer-timer;

cout<<"You drew a circle in "<< seconds<< " seconds"<< endl;
}
else
{
cout<< "Maybe you'll try next time. Thanks for viewing my demo"<< endl;
}


enjoy(like);

input(seconds, robSeconds, like, rating, userTime, robTime, counter);
output(rating, userTime, robTime, counter);

cout<<"Would you like to try drawing something on your own?"<< endl;
cout<<"Press A if you want to. Press B if you don't"<< endl;
cin>>choice;
cout<<
endl;

if (choice == 'a')
{
joystick(timer);

}
else
{
cout<<"Thanks for playing"<< endl;
}
disconnect();
evaluation(rating, userTime, robTime);

return 0;
}

[Lab 7 code]

#include
#include
#include
#include

using namespace std;

int main(){

connect();

double x = 120/136.5;
double q = 120/136.5;
double g = 121/136.5;

double a = 12.0/5.8;
double b = 9.0/5.6;

double d = 3.0/7.9;

robot.forward(1.0, a);
robot.turnRight(1.0, x);
robot.forward(1.0, a);
robot.turnRight(1.0, q);
robot.forward(1.0, b);
robot.turnRight(1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.forward(1.0, d);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);

robot.turnLeft (1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.forward(1.0, d);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.forward(1.0, d);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.forward(1.0, d);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.forward(1.0, d);
robot.turnLeft(1.0, g);
robot.forward(1.0, d);
robot.turnRight(1.0, g);
robot.forward(1.0, d);

disconnect();

return 0;
}

The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees