Homepage for USC Student Lauren Egan
//main program HCI-laureneg.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <Myro.h>
#include <Graphics.h>
using namespace std;
#include "interface.h"
#include "user.h"
void beginScreen(User &user, bool &yes);
void runQuestions(User &user);
void editPhoto(User &user);
void outputResults(User &user);
void fileHandling(User &user);
int main ()
{
bool proceed;
User student;
string name;
connect("/dev/ttyS0");
//loop so student can continue if they desire
do
{
cout << "What is your name?" << endl;
cin >> name;
student.setUserName(name);
beginScreen(student, proceed);
if (proceed == 0)
break;
runQuestions(student);
editPhoto(student);
fileHandling(student);
outputResults(student);
} while (proceed == 1);
disconnect();
return 0;
}
//function that opens a window with instructions
void beginScreen (User &user, bool &yes)
{
GraphWin window("begin", 800, 500);
PicturePtr begin = loadPicture ("begin.jpg");
window.setBackground(begin);
window.update();
Point m;
while (!window.isClosed()){
m = window.getMouse();
if ((m.getX() > 300) && (m.getX() < 500) &&
(m.getY() > 350) && (m.getY() < 450) )
{
yes = 1;
wait(2);
robot.beep(.25, 440);
PicturePtr img = robot.takePicture("jpeg");
string originaltitle = "original";
originaltitle += user.getUserName();
originaltitle += ".jpg";
savePicture(img, originaltitle.c_str());
user.setJpegName(originaltitle.c_str());
break;
}
if ((m.getX() < 300 || m.getX() > 500 ||
m.getY() < 350 || m.getY() > 450))
{
yes = 0;
wait(1);
break;
}
}
window.close();
}
//function that opens the question interfaces and stores user input
void runQuestions (User &user)
{
int numCorrect = 0;
int correct[5];
for (int i = 0; i < 5; i++)
{
correct[i] = 0;
}
Interface one, two, three, four, five;
one.setJpegName("q1.jpg");
one.setCorrectChoice(1);
one.createInterface();
if (one.getUserChoice() == one.getCorrectChoice())
{
numCorrect++;
correct[0] = 1;
}
two.setJpegName("q2.jpg");
two.setCorrectChoice(3);
two.createInterface();
if (two.getUserChoice() == two.getCorrectChoice())
{
numCorrect++;
correct[1] = 1;
}
three.setJpegName("q3.jpg");
three.setCorrectChoice(3);
three.createInterface();
if (three.getUserChoice() == three.getCorrectChoice())
{
numCorrect++;
correct[2] = 1;
}
four.setJpegName("q4.jpg");
four.setCorrectChoice(2);
four.createInterface();
if (four.getUserChoice() == four.getCorrectChoice())
{
numCorrect++;
correct[3] = 1;
}
five.setJpegName("q5.jpg");
five.setCorrectChoice(4);
five.createInterface();
if (five.getUserChoice() == five.getCorrectChoice())
{
numCorrect++;
correct[4] = 1;
}
user.setNumberCorrect(numCorrect);
user.setResults(correct);
}
void editPhoto(User &user)
{
string name;
name = user.getJpegName();
PicturePtr pic = loadPicture(name.c_str());
Pixel p1;
show (pic);
if (user.getNumberCorrect() > 2)
{
Interface color;
color.setJpegName("colorchoice.jpg");
color.createInterface();
if (color.getUserChoice() == 1)
{
//blue
p1.R = 0;
p1.G = 0;
p1.B = 255;
}
if (color.getUserChoice() == 2)
{
//orange
p1.R = 255;
p1.G = 128;
p1.B = 0;
}
if (color.getUserChoice() == 3)
{
//green
p1.R = 0;
p1.G = 255;
p1.B = 0;
}
if (color.getUserChoice() == 4)
{
//purple
p1.R = 255;
p1.G = 0;
p1.B = 255;
}
}
else
{
p1.R = 0;
p1.G = 0;
p1.B = 255;
}
int height, width;
height = getHeight(pic);
width = getWidth(pic);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
Pixel p = pic->getPixel(i,j);
p.R = (p.R + p1.R)/2;
p.G = (p.G + p1.G)/2;
p.B = (p.B + p1.B)/2;
setPixelColor(pic,i,j,(double)p.R,(double)p.G,(double)p.B);
}
}
show (pic);
string edittitle = "edit";
edittitle += user.getUserName();
edittitle += ".jpg";
user.setEditedJpegName(edittitle);
savePicture(pic, edittitle.c_str());
}
//function that outputs results in a table window
void outputResults(User &user)
{
//retrives the results
int tableValues[5], *ptr;
ptr = user.getResults();
for (int i = 0; i < 5; i++)
{
tableValues[i] = *ptr;
ptr++;
}
string title = "Output Results for ";
title += user.getUserName();
GraphWin result(title.c_str(), 800, 500);
result.setBackground("dark turquoise");
Point setTitleLocation (10, 10);
Text setTitle (setTitleLocation, title);
setTitle.setTextColor ("white");
setTitle.setFace("arial");
setTitle.setSize(50);
setTitle.draw(result);
//points and lines to set up the chart lines
Point a(100, 100);
Point b(300, 100);
Point c(500, 100);
Point d(700, 100);
Point e(100, 150);
Point f(700, 150);
Point g(100, 200);
Point h(700, 200);
Point i(100, 250);
Point j(700, 250);
Point k(100, 300);
Point l(700, 300);
Point m(100, 350);
Point n(700, 350);
Point o(100, 400);
Point p(300, 400);
Point q(500, 400);
Point s(700, 400);
Line ad(a, d);
ad.setFill("white");
ad.setOutline("white");
ad.setWidth(2);
ad.draw(result);
Line ef(e, f);
ef.setFill("white");
ef.setOutline("white");
ef.setWidth(2);
ef.draw(result);
Line gh(g, h);
gh.setFill("white");
gh.setOutline("white");
gh.setWidth(2);
gh.draw(result);
Line ij(i, j);
ij.setFill("white");
ij.setOutline("white");
ij.setWidth(2);
ij.draw(result);
Line kl(k, l);
kl.setFill("white");
kl.setOutline("white");
kl.setWidth(2);
kl.draw(result);
Line mn(m, n);
mn.setFill("white");
mn.setOutline("white");
mn.setWidth(2);
mn.draw(result);
Line os(o, s);
os.setFill("white");
os.setOutline("white");
os.setWidth(2);
os.draw(result);
Line ao(a, o);
ao.setFill("white");
ao.setOutline("white");
ao.setWidth(2);
ao.draw(result);
Line bp(b, p);
bp.setFill("white");
bp.setOutline("white");
bp.setWidth(2);
bp.draw(result);
Line cq(c, q);
cq.setFill("white");
cq.setOutline("white");
cq.setWidth(2);
cq.draw(result);
Line ds(d, s);
ds.setFill("white");
ds.setOutline("white");
ds.setWidth(2);
ds.draw(result);
//setting appropriate text in table cells
Point setQuestionLocation(140, 110);
string question = "Question";
Text setQuestion(setQuestionLocation, question);
setQuestion.setTextColor ("white");
setQuestion.setFace("arial");
setQuestion.setSize(35);
setQuestion.draw(result);
Point setOneLocation (190, 160);
string one = "1";
Text setOne (setOneLocation, one);
setOne.setTextColor("white");
setOne.setFace("arial");
setOne.setSize(35);
setOne.draw(result);
Point setTwoLocation (190, 210);
string two = "2";
Text setTwo (setTwoLocation, two);
setTwo.setTextColor("white");
setTwo.setFace("arial");
setTwo.setSize(35);
setTwo.draw(result);
Point setThreeLocation (190, 260);
string three = "3";
Text setThree (setThreeLocation, three);
setThree.setTextColor("white");
setThree.setFace("arial");
setThree.setSize(35);
setThree.draw(result);
Point setFourLocation (190, 310);
string four = "4";
Text setFour (setFourLocation, four);
setFour.setTextColor("white");
setFour.setFace("arial");
setFour.setSize(35);
setFour.draw(result);
Point setFiveLocation (190, 360);
string five = "5";
Text setFive (setFiveLocation, five);
setFive.setTextColor("white");
setFive.setFace("arial");
setFive.setSize(35);
setFive.draw(result);
Point setCorrectLocation(340, 110);
string correct = "Correct?";
Text setCorrect(setCorrectLocation, correct);
setCorrect.setTextColor("white");
setCorrect.setFace("arial");
setCorrect.setSize(35);
setCorrect.draw(result);
Point setIncorrectLocation(530, 110);
string incorrect = "Incorrect?";
Text setIncorrect(setIncorrectLocation, incorrect);
setIncorrect.setTextColor("white");
setIncorrect.setFace("arial");
setIncorrect.setSize(35);
setIncorrect.draw(result);
int x;
//location of text depends on whether the user was correct
if (tableValues[0])
x = 390;
else
x = 590;
Point set1Location(x, 160);
Text set1 (set1Location, "X");
set1.setTextColor("white");
set1.setFace("arial");
set1.setSize(35);
set1.draw(result);
if (tableValues[1])
x = 390;
else
x = 590;
Point set2Location(x, 210);
Text set2(set2Location, "X");
set2.setTextColor("white");
set2.setFace("arial");
set2.setSize(35);
set2.draw(result);
if (tableValues[2])
x = 390;
else
x = 590;
Point set3Location(x, 260);
Text set3(set3Location, "X");
set3.setTextColor("white");
set3.setFace("arial");
set3.setSize(35);
set3.draw(result);
if (tableValues[3])
x = 390;
else
x = 590;
Point set4Location(x, 310);
Text set4(set4Location, "X");
set4.setTextColor("white");
set4.setFace("arial");
set4.setSize(35);
set4.draw(result);
if (tableValues[4])
x = 390;
else
x = 590;
Point set5Location(x, 360);
Text set5(set5Location, "X");
set5.setTextColor("white");
set5.setFace("arial");
set5.setSize(35);
set5.draw(result);
Point setCloseLocation(10, 420);
string close = "Please close the window when you are finished viewing the results.";
Text setClose (setCloseLocation, close);
setClose.setTextColor("white");
setClose.setFace("arial");
setClose.setSize(25);
setClose.draw(result);
result.waitWinClosed();
}
void fileHandling(User &user)
{
string *info, temp;
int lines = 0, results[5], *p = user.getResults();
for (int i = 0; i < 5; i++)
{
results[i] = *p;
p++;
}
//figure out number of lines in text file
ifstream inputFile;
inputFile.open("info.txt");
while (!inputFile.eof())
{
getline(inputFile, temp);
lines++;
}
inputFile.close();
lines += 1;
info = new string[lines];
inputFile.open("info.txt");
for (int i = 0; i < lines - 1; i++)
{
getline(inputFile, info[i]);
}
inputFile.close();
string temp2;
for (int i = 0; i < 5; i++)
{
ostringstream convert;
convert << results[i];
temp2 = convert.str();
info[lines-1] += temp2 + " ";
}
info [lines-1] += user.getUserName() + " ";
info[lines-1] += user.getJpegName() + " ";
info[lines-1] += user.getEditedJpegName();
ofstream SaveFile ("info.txt");
for (int i = 0; i < lines; i++)
{
if (i != lines - 1)
SaveFile << info[i] << endl;
else
SaveFile << info[i];
}
SaveFile.close();
}
//interface.cpp
#include <iostream>
#include <Myro.h>
#include <Graphics.h>
#include <cstring>
#include <sstream>
using namespace std;
#include "interface.h"
Interface::Interface()
{
jpegName = "";
userChoice = 0;
correctChoice = 0;
}
Interface::~Interface()
{}
string Interface::getJpegName()
{
return jpegName;
}
int Interface::getUserChoice()
{
return userChoice;
}
int Interface::getCorrectChoice()
{
return correctChoice;
}
void Interface::setJpegName(string j)
{
jpegName = j;
}
void Interface::setUserChoice(int uc)
{
userChoice = uc;
}
void Interface::setCorrectChoice(int c)
{
correctChoice = c;
}
void Interface::createInterface()
{
GraphWin window(jpegName, 800, 500);
//opens appropriate interface image I created
PicturePtr question = loadPicture (jpegName.c_str());
window.setBackground(question);
window.update();
Point m;
//gets location of user click to store input
while (!window.isClosed()){
m = window.getMouse();
if ((m.getX() > 100) && (m.getX() < 400) &&
(m.getY() > 210) && (m.getY() < 347))
{
userChoice = 1;
}
if ((m.getX() > 100) && (m.getX() < 400) &&
(m.getY() > 347) && (m.getY() < 485))
{
userChoice = 2;
}
if ((m.getX() > 400) && (m.getX() < 700) &&
(m.getY() > 210) && (m.getY() < 347))
{
userChoice = 3;
}
if ((m.getX() > 400) && (m.getX() < 700) &&
(m.getY() > 347) && (m.getY() < 485))
{
userChoice = 4;
}
if ((m.getX() < 100 || m.getX() > 700 ||
m.getY() < 210 || m.getY() > 485))
break;
if (userChoice != 0)
{
break;
}
}
wait(1);
window.close();
}
//interface.h
class Interface {
public:
Interface();
~Interface();
string getJpegName();
int getUserChoice();
int getCorrectChoice();
void setJpegName(string j);
void setUserChoice(int uc);
void setCorrectChoice (int c);
void createInterface();
private:
string jpegName;
int userChoice;
int correctChoice;
};
//user.cpp
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;
#include "user.h"
User::User()
{
jpegName = "";
editedJpegName = "";
userName = "";
numberCorrect = 0;
for (int i = 0; i < 5; i++)
results[i]=0;
}
User::~User()
{}
string User::getJpegName()
{
return jpegName;
}
string User::getEditedJpegName()
{
return editedJpegName;
}
string User::getUserName()
{
return userName;
}
int User::getNumberCorrect()
{
return numberCorrect;
}
int* User::getResults()
{
return results;
}
void User::setJpegName(string j)
{
jpegName = j;
}
void User::setEditedJpegName(string ej)
{
editedJpegName = ej;
}
void User::setUserName(string n)
{
userName = n;
}
void User::setNumberCorrect (int n)
{
numberCorrect = n;
}
void User::setResults(int r[])
{
for (int i = 0; i < 5; i++)
results[i]=r[i];
}
//user.h
class User {
public:
User();
~User();
string getJpegName();
string getEditedJpegName();
string getUserName();
int getNumberCorrect();
int *getResults();
void setJpegName(string j);
void setEditedJpegName(string ej);
void setUserName(string n);
void setNumberCorrect (int n);
void setResults(int r[]);
private:
string jpegName;
string editedJpegName;
string userName;
int numberCorrect;
int results[5];
};
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