Cullen Riley's Website

Cullen Riley

Cullen Riley

=================================================

Email: cullenri@usc.edu

This Is My Robot

Interface

Robot Demo

In this demo, the user answers a series of sports related trivia questions. For each question
answered correctly, the robot moves forward for each question answered incorrectly, the robot
moves backward. The interface is a box for A, B, C, and D that the user can click on to select
the correct answer. At the end the user's time is outputed.Then the program asks the user how
they enjoyed the game and plots this data on a graph of circles that are scaled in proportion to
the number of users that selected that option.
Interface

HW6.cpp

#include 
#include 
#include 
#include 
#include 
#include 
#include "question.h"
#include 

using namespace std;

void loadQuestions(vector &allQuestions);
void stepBackward(string command);
void stepForward(string command);
bool displayQuestion(question *currentQuestion, GraphWin &menu, Point &lastClick);
int getMouse(GraphWin &menu, Point &lastClick);
void readRatings(int userSRatings[]);
void graphUserRatings(int userSRatings[], GraphWin &data);
void dataCollection(int userSRatings[]);
void writeUserData(int userSRatings[]);

int main(){
	connect();
	vector allQuestions;//vector to store all the class objects
	loadQuestions(allQuestions);
	bool notDone=true;//bool variable for the while loop that points the user back to the menu function
	GraphWin menu("Choose Answer", 225, 225, true); //create menu object
	menu.setBackground(loadPicture("images.jpeg")); //set BG picture
    //check to see if user wants to repeat
    while(notDone){
    	clock_t t1,t2;
    	t1=clock();//gets time 1
		Point lastClick;
		for(int i=0; igetDirections());
			}
			//if not go backwards and display previous question
			else if(i-1>=0){
				stepBackward(allQuestions[i-1]->getDirections());
				i=i-2;
			}
			//if missed first question then stay at that question
			else{
				i=i-1;
			}
		}
		t2=clock();//gets time 2
    	float diff ((float)t2-(float)t1);//finds the difference between time one and two
    	cout<<"Your time was: "<>yesNo;
	    if(yesNo=='n'){
	        notDone=false;//exits loop
	    }
	}
	disconnect();
	return 0;
}
//loads the questions, answers, and solutions into the components of the class using set-functions
//also loads the directions for the robot
void loadQuestions(vector &allQuestions){
	question *question1=new question;//new object
	question1->setDirections("F 1.79");//directions
	question1->setQuestions("1) Who won the super bowl last year?");//question
	//answers
	question1->setAnswer1("San Francisco 49ers");
	question1->setAnswer2("New England Patriots");
	question1->setAnswer3("Detroit Lions");
	question1->setAnswer4("New York Giants");
	//solution
	question1->setQSolution(1);
	allQuestions.push_back(question1);//stores object in vector
	
	question *question2=new question;
	question2->setDirections("L .74");
	question2->setQuestions("2) How many olympic medals has Michael Phelps won?");
	question2->setAnswer1("18");
	question2->setAnswer2("22");
	question2->setAnswer3("3");
	question2->setAnswer4("12");
	question2->setQSolution(2);
	allQuestions.push_back(question2);

	question *question3=new question;
	question3->setDirections("F 2.9");
	question3->setQuestions("3) Who is the best female tennis player of all time");
	question3->setAnswer1("Maria Sharapova");
	question3->setAnswer2("Serna Williams");
	question3->setAnswer3("Venus Williams");
	question3->setAnswer4("Steffi Graf");
	question3->setQSolution(4);
	allQuestions.push_back(question3);

	question *question4=new question;
	question4->setDirections("R .74");
	question4->setQuestions("4) Who was USC's quarterback last season?");
	question4->setAnswer1("Micheal Jordan");
	question4->setAnswer2("Matt Barkley");
	question4->setAnswer3("Mark Sanchez");
	question4->setAnswer4("Tom Brady");
	question4->setQSolution(2);
	allQuestions.push_back(question4);

	question *question5=new question;
	question5->setDirections("F 1.38");
	question5->setQuestions("5) What hockey team has won the most stanley cups?");
	question5->setAnswer1("Toronto Maple Leafs");
	question5->setAnswer2("Boston Bruins");
	question5->setAnswer3("Montreal Canadians");
	question5->setAnswer4("LA Kings");
	question5->setQSolution(3);
	allQuestions.push_back(question5);

	question *question6=new question;
	question6->setDirections("R .74");
	question6->setQuestions("6) Who won the most recent Fifa World Cup?");
	question6->setAnswer1("Spain");
	question6->setAnswer2("Brazil");
	question6->setAnswer3("Netherlands");
	question6->setAnswer4("Germany");
	question6->setQSolution(1);
	allQuestions.push_back(question6);

	question *question7=new question;
	question7->setDirections("F 2.9");
	question7->setQuestions("7) What baseball player has hit the most home runs of all time?");
	question7->setAnswer1("Barry Bonds");
	question7->setAnswer2("Babe Ruth");
	question7->setAnswer3("Hank Aaron");
	question7->setAnswer4("Alex Rodriguez");
	question7->setQSolution(1);
	allQuestions.push_back(question7);

	question *question8=new question;
	question8->setDirections("L .74");
	question8->setQuestions("8) What NHL player has the most points of all time?");
	question8->setAnswer1("Mark Messier");
	question8->setAnswer2("Joe Sacik");
	question8->setAnswer3("Alexander Ovetchkin");
	question8->setAnswer4("Wayne Gretzky");
	question8->setQSolution(4);
	allQuestions.push_back(question8);

	question *question9=new question;
	question9->setDirections("F 1.35");
	question9->setQuestions("9) What country is Usain Bolt from?");
	question9->setAnswer1("America");
	question9->setAnswer2("Brazil");
	question9->setAnswer3("Jamaica");
	question9->setAnswer4("Nigeria");
	question9->setQSolution(3);
	allQuestions.push_back(question9);

	question *question10=new question;
	question10->setDirections("L.76");
	question10->setQuestions("10) What team won the NBA Championship last year?");
	question10->setAnswer1("Heat");
	question10->setAnswer2("Lakers");
	question10->setAnswer3("Celtics");
	question10->setAnswer4("Bruins");
	question10->setQSolution(1);
	allQuestions.push_back(question10);

	question *question11=new question;
	question11->setDirections("F 2.9");
	question11->setQuestions("11) What country won the gold medal in ice hockey last year?");
	question11->setAnswer1("Germany");
	question11->setAnswer2("Russia");
	question11->setAnswer3("America");
	question11->setAnswer4("Canada");
	question11->setQSolution(4);
	allQuestions.push_back(question11);

	question *question12=new question;
	question12->setDirections("R .74");
	question12->setQuestions("12) What team does Kobe Bryant play for?");
	question12->setAnswer1("Heat");
	question12->setAnswer2("Nicks");
	question12->setAnswer3("Lakers");
	question12->setAnswer4("Majic");
	question12->setQSolution(3);
	allQuestions.push_back(question12);

	question *question13=new question;
	question13->setDirections("F 1.4");
	question13->setQuestions("13) Which team was your favorite team?");
	question13->setAnswer1("Team 11");
	question13->setAnswer2("Team 11");
	question13->setAnswer3("Team 11");
	question13->setAnswer4("Team 11");
	question13->setQSolution(-1);
	allQuestions.push_back(question13);
}
//displays question called by for loop and returns true if user answers correctly
bool displayQuestion(question *currentQuestion,GraphWin &menu, Point &lastClick){
	menu.update();
	//uses get functions to display
	cout<getQuestions()<getAnswer1()<getAnswer2()<getAnswer3()<getAnswer4()<getQSolution()==-1){
 		return true;
 	}
 	//if click return correct solution return true
 	if (button==currentQuestion->getQSolution())
	{    
		return true;
	}
	//if click return wrong solution return false
 	else{
		return false;
	}
}
//takes in the F B R or L and converts it to a robot action
//each letter is givven pixel ranges that correspond to the picture
//each leter is assigned a number that is returned depending on where is clicked
int getMouse(GraphWin &menu, Point &lastClick){
	Point click;
    click = menu.getMouse();
    if(lastClick.getX() != click.getX() && lastClick.getY()!= click.getY())
    {
    	lastClick = click;
		if (click.getX() < 110 && click.getY() < 110) return 1;
	    else if (click.getX() < 110 && click.getY() > 115) return 3;
	    else if (click.getX() > 115 && click.getY() < 110) return 2;
	    else return 4;
	}
    return 0;
}
//perfomes the action of the previous question backwards
void stepBackward(string command){
	stringstream ss;
	ss<>dir;
		ss>>duration;
		switch(dir){
		case 'F':
			robot.backward(1, duration);
			cout<>dir;
		ss>>duration;
		switch(dir){
		case 'F':
			robot.forward(1, duration);
			cout<>input;
	//checks what that input is and then increents that star value by one
	if(input==1){
		userSRatings[0]=userSRatings[0]+1;
	}
	else if(input==2){
		userSRatings[1]=userSRatings[1]+1;
	}
	else if(input==3){
		userSRatings[2]=userSRatings[2]+1;
	}
	else if(input==4){
		userSRatings[3]=userSRatings[3]+1;
	}
	else if(input==5){
		userSRatings[4]=userSRatings[4]+1;
	}
	else{
		cout<<"Invalid input"<

question.h

#include 

using namespace std;

class question{
private:
	string directions;
	string questions;
	string answer1;
	string answer2;
	string answer3;
	string answer4;
	int qSolution;

public:
	question(string directions, string questions, string answer1, string answer2, string answer3, string answer4, int qSolution);
	question();
	~question();
	void setDirections(string directions) { this->directions = directions; } 
	string getDirections() { return this->directions; }
	void setQuestions(string questions) { this->questions = questions; } 
	string getQuestions() { return this->questions; }
	void setAnswer1(string answer1) { this->answer1 = answer1; } 
	string getAnswer1() { return this->answer1; }
	void setAnswer2(string answer2) { this->answer2 = answer2; } 
	string getAnswer2() { return this->answer2; }
	void setAnswer3(string answer3) { this->answer3 = answer3; } 
	string getAnswer3() { return this->answer3; }
	void setAnswer4(string answer4) { this->answer4 = answer4; } 
	string getAnswer4() { return this->answer4; }
	void setQSolution(int qSolution) { this->qSolution = qSolution; } 
	int getQSolution() { return this->qSolution; }
};

question.cpp

#include 
#include "question.h"

using namespace std;

question::question(string indirections, string inquestions, string inanswer1, string inanswer2, string inanswer3, string inanswer4, int inqSolution){
	directions=indirections;
	questions=inquestions;
	answer1=inanswer1;
	answer2=inanswer2;
	answer3=inanswer3;
	answer4=inanswer4;
	qSolution=inqSolution;
}

question::question(){
	
}

Lab 7 Demo

Lab_7.cpp

This program draws Siierpensky triangles. The robots batteries were a little inconsistent at the
time i filmed this and it seemed draw slightly differently everytime but it was fairly close.
#include
#include

using namespace std;

int main(){
	connect();
	char random;
	cin>>random;
	robot.forward(1, 1.2);
	robot.turnLeft(1,.5);
	robot.backward(1, 1.2);
	robot.turnRight(1,.5);
	robot.backward(1,1.2);
	robot.turnLeft(1, .5);
	robot.forward(1, .6);
	robot.turnRight(1,.5);
	robot.forward(1, .6);
	robot.turnLeft(1, .5);
	robot.backward(1,.6);
	robot.turnLeft(1, .5);
	robot.forward(1, .6);
	robot.turnRight(1,.5);
	robot.forward(1, 1.8);
	robot.turnLeft(1, .5);
	robot.backward(1,.6);
	robot.turnLeft(1, .5);
	robot.forward(1, .6);
	robot.turnRight(1, .5);
	robot.backward(1, .6);
	robot.turnRight(1, .5);
	robot.forward(1, .6);
	robot.turnLeft(1, .5);
	robot.backward(1, 2);
	robot.turnLeft(1, .5);
	robot.forward(1, .6);
	robot.turnLeft(1, .5);
	robot.backward(1, .6);
	robot.turnRight(1, .5);
	robot.forward(1, .6);
	robot.turnRight(1, .5);
	robot.backward(1, .6);
	robot.turnLeft(1, .5);
	robot.forward(1, .6);
	robot.turnRight(1, .5);
	robot.forward(1, 1.2);
	disconnect();
}

Lecture Exercise

Interface

square.cpp

 #include 
#include 
#include "interface.h"
#include "interface.cpp"

//g++ `myro-cpp-config --cflags` Square.cpp `myro-cpp-config --libs` -o Square

using namespace std;

int main(){
GraphWin win("Square", 500, 500);
Point anchor(20,20);
Image square(anchor,"Square.jpeg");
square.draw(win);
win.update();
while(!win.isClosed()){
Point click=win.checkMouse();
if (click.getX() >= 0 && click.getY() >= 0){
connect();
//setName(robot);
robot.move(.5,0);
wait(1.75); 
robot.hardStop();
robot.rotate(.83);
wait(1);
robot.move(.5,0);
wait(1.75);
robot.hardStop();
robot.rotate(.83);
wait(1);
robot.move(.5,0);
wait(1.75); 
robot.hardStop();
robot.rotate(.83);
wait(1);
robot.move(.5,0);
wait(1.75);
disconnect();
}
}
return0;
}

interface.h

#include
#include 

usingnamespace std;

class Interface{
public:
	Interface();
	~Interface();
	void set_interface_name(string inName);
	string get_interface_name();
	void set_numIcons(int inIcons);
	int get_numIcons();
	vector fillNamesOfJPGs();
	void createInterface(vector jpgNames, string inName);
private:
	string interfaceName;
	vectornamesOfJPGs;
	int numIcons;
};

interface.cpp

#include "interface.h"
usingnamespace std;
using std::vector;

Interface:: Interface()
{
interfaceName="";
numIcons=0;
}
Interface:: ~Interface()
{

}
void set_Interface_name(string inName)
{
interfaceName=inName;
}

string get_interface_name()
{
return interfaceName;
}
void set_numIcons(int inIcons)
{
numIcons=inIcons;
}
int get_numIcons()
{
return numIcons;
}
vector fillNamesOfJPGs()
{
int numberIcons=getNumIcons();
vectorjpgNames;
for(int i=0;i>temp;
jpgNames.pushback(temp);
}
}
void createInterface(vectorjpgNames, string inName, Point anchor)
{
GraphWin win(name, 500, 500);
robot.setForwardness("fluke-forward");
Image hello(anchor,jpgNames[0]);
}