Links:

Lab 5

Partners:

Ryan Stack
Ena Trokic
Victoria Dea

My code takes user input to populate the array of 20, and then plays the songs in the order selected by the user.

                    #include 
                        #include 
                            #include 
                                #include 
                                    #include 
                                        
                                        using namespace std;
                                        
                                        int playlist[20];
                                        int drawing[4];
                                        void hotelCalifornia() //Ryan's piece
                                        {
                                        double beat = 60.0/180.0;
                                        double a = 220*2;
                                        double as = 233.08*2;
                                        double b = 246.94*2;
                                        double c = 261.63*2;
                                        double cs = 277.18*2;
                                        double d = 293.66*2;
                                        double ds = 311.13*2;
                                        double e = 329.63*2;
                                        double f = 349.23*2;
                                        double fs = 369.99*2;
                                        double g = 392.00*2;
                                        double gs = 415.30*2;
                                        
                                        robot.beep(beat*1.5, d*2.0);
                                        robot.beep(beat*.5, fs);
                                        robot.beep(beat*.5,b*2.0);
                                        robot.beep(beat*.5,d*2.0);
                                        robot.beep(beat*.5,b*2.0);
                                        robot.beep(beat*.5,fs);
                                        //
                                        robot.beep(beat*1.5,d*2.0);
                                        robot.beep(beat*.5,b);
                                        robot.beep(beat,d);
                                        robot.beep(beat,e);
                                        //
                                        robot.beep(beat,as*2.0);
                                        robot.beep(beat*.5,cs);
                                        robot.beep(beat*.5,as*2.0);
                                        robot.beep(beat*.5,cs*2.0);
                                        robot.beep(beat*.5,as*2.0);
                                        robot.beep(beat,cs);
                                        //
                                        robot.beep(beat*4.0,as*2.0);
                                        //
                                        robot.beep(beat*1.5,a*2.0);
                                        robot.beep(beat*.5,a);
                                        robot.beep(beat*.5,e);
                                        robot.beep(beat*.5,b*2);
                                        robot.beep(beat*.5,e);
                                        robot.beep(beat*.5,a);
                                        //
                                        robot.beep(beat,a*2.0);
                                        robot.beep(beat*.5,a);
                                        robot.beep(beat*.5,a*2.0);
                                        robot.beep(beat,e);
                                        robot.beep(beat,a);
                                        //
                                        robot.beep(beat,fs);
                                        robot.beep(beat*.5,gs*.5);
                                        robot.beep(beat,d);
                                        robot.beep(beat*.5,fs);
                                        robot.beep(beat*.5,d);
                                        //
                                        robot.beep((beat*.5)+(beat*4.0),gs*.5);
                                        //
                                        robot.beep(beat,g);
                                        robot.beep(beat*.5,g*.5);
                                        robot.beep(beat,d);
                                        robot.beep(beat*.5,g);
                                        robot.beep(beat*.5,d);
                                        robot.beep(beat*.5,g*.5);
                                        //
                                        robot.beep(beat, b*2.0);
                                        robot.beep(beat*.5,d);
                                        robot.beep(beat,g);
                                        robot.beep(beat,g*.5);
                                        //
                                        robot.beep(beat,a*2.0);
                                        robot.beep(beat*.5,a);
                                        robot.beep(beat,fs);
                                        robot.beep(beat*.5,a*2.0);
                                        robot.beep(beat*.5,d);
                                        robot.beep(beat*.5,a);
                                        //
                                        robot.beep(beat*2.0,a*2.0);
                                        robot.beep(beat*2.0,d);
                                        //
                                        robot.beep(beat, e);
                                        robot.beep(beat*.5, e*.5);
                                        robot.beep(beat,b);
                                        robot.beep(beat*.5,e);
                                        robot.beep(beat*.5,b);
                                        robot.beep(beat*.5, e*.5);
                                        //
                                        robot.beep(beat,e);
                                        robot.beep(beat*.5,e*.5);
                                        robot.beep(beat*.5,b);
                                        robot.beep(beat,e);
                                        robot.beep(beat,g*.5);
                                        //
                                        robot.beep(beat,fs);
                                        robot.beep(beat*.5,fs*.5);
                                        robot.beep((beat*.5)+(beat*2.0),as);
                                        //
                                        robot.beep(beat*2.0, fs);
                                        robot.beep(.1, g*6.0);
                                        wait(beat);
                                        robot.beep(.1, g*6.0);
                                        }
                                        void odeToJoy() // Victoria's piece
                                        {
                                        robot.beep(.5,659.3);
                                        robot.beep(.5,659.3);
                                        robot.beep(.5,698.5);
                                        robot.beep(.5,784);
                                        
                                        robot.beep(.5,784);
                                        robot.beep(.5,698.5);
                                        robot.beep(.5,659.3);
                                        robot.beep(.5,587.3);
                                        
                                        robot.beep(.5,523.3);
                                        robot.beep(.5,523.3);
                                        robot.beep(.5,587.3);
                                        robot.beep(.5,659.3);
                                        
                                        robot.beep(.5,659.3);
                                        robot.beep(.25,587.3);
                                        robot.beep(.75,587.3);
                                        wait(.5);
                                        
                                        robot.beep(.5,659.3);
                                        robot.beep(.5,659.3);
                                        robot.beep(.5,698.5);
                                        robot.beep(.5,784);
                                        
                                        robot.beep(.5,784);
                                        robot.beep(.5,698.5);
                                        robot.beep(.5,659.3);
                                        robot.beep(.5,587.3);
                                        
                                        robot.beep(.5,523.3);
                                        robot.beep(.5,523.3);
                                        robot.beep(.5,587.3);
                                        robot.beep(.5,659.3);
                                        
                                        robot.beep(.5,587.3);
                                        robot.beep(.3,523.3);
                                        robot.beep(.75,523.3);
                                        wait(2);
                                        }
                                        void randomSong() // My piece
                                        {
                                        int noteNum;
                                        int beatNum;
                                        for(int i = 1; i < 32; i++) //Randomly Generated Song, 32 Notes
                                            {
                                            
                                            noteNum = rand() % 7 + 1;
                                            beatNum = rand() % 4;
                                            if(noteNum == 1)
                                            {
                                            //A
                                            robot.beep(beatNum*0.5,880.00);
                                            cout << "A, " ;
                                            }
                                            else if(noteNum == 2)
                                            {
                                            //B
                                            robot.beep(beatNum*0.5,987.77);
                                            cout << "B, " ;
                                            }
                                            else if(noteNum == 3)
                                            {
                                            //C
                                            robot.beep(beatNum*0.5,1046.50);
                                            cout << "C, ";
                                            }
                                            else if(noteNum == 4)
                                            {
                                            //D
                                            robot.beep(beatNum*0.5,1174.66);
                                            cout << "D, " ;
                                            }
                                            else if(noteNum == 5)
                                            {
                                            //E
                                            robot.beep(beatNum*0.5,1318.51);
                                            cout << "E, ";
                                            }
                                            else if(noteNum == 6)
                                            {
                                            //F
                                            robot.beep(beatNum*0.5,1396.91);
                                            cout << "F, " ;
                                            }
                                            else if(noteNum == 7)
                                            {
                                            //G
                                            robot.beep(beatNum*0.5,1567.98);
                                            cout << "G, " ;
                                            }
                                            }
                                            }
                                            void twinkle() // Ena's piece
                                            {
                                            robot.beep(0.5,523.25);
                                            robot.beep(0.5,523.25);
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,880);
                                            robot.beep(0.5,880);
                                            robot.beep(1,783.99);
                                            
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,659.26);
                                            robot.beep(0.5,659.26);
                                            robot.beep(0.5,587.33);
                                            robot.beep(0.5,587.33);
                                            robot.beep(1,523.25);
                                            
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,659.26);
                                            robot.beep(0.5,659.26);
                                            robot.beep(1,587.33);
                                            
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,659.26);
                                            robot.beep(0.5,659.26);
                                            robot.beep(1,587.33);
                                            
                                            robot.beep(0.5,523.25);
                                            robot.beep(0.5,523.25);
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,783.99);
                                            robot.beep(0.5,880);
                                            robot.beep(0.5,880);
                                            robot.beep(1,783.99);
                                            
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,698.46);
                                            robot.beep(0.5,659.26);
                                            robot.beep(0.5,659.26);
                                            robot.beep(0.5,587.33);
                                            robot.beep(0.5,587.33);
                                            robot.beep(1,523.25);
                                            }
                                            void fightOn() // Collective piece
                                            {
                                            int tempo = 176;
                                            double beat = (60.0/tempo);
                                            
                                            robot.beep((1.0/3.0)*beat,1046.50);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            //1
                                            robot.beep((2.0)*beat,1046.50);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,880.000);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,932.328);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,783.991);
                                            robot.beep((0)*beat,0.0);
                                            //2
                                            robot.beep((2)*beat,880.000);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,698.456);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,659.255);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,587.330);
                                            robot.beep((0)*beat,0.0);
                                            //3
                                            robot.beep((2)*beat,523.251);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,880.000);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,932.328);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,659.255);
                                            robot.beep((0)*beat,0.0);
                                            //4
                                            robot.beep((2)*beat,698.456);
                                            robot.beep((1)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,1046.50);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            //5
                                            robot.beep((2)*beat,1046.50);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,880.000);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,932.328);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,783.991);
                                            robot.beep((0)*beat,0.0);
                                            //6
                                            robot.beep((2)*beat,880.000);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,698.456);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,659.255);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,587.330);
                                            robot.beep((0)*beat,0.0);
                                            //7
                                            robot.beep((2)*beat,523.251);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,880.000);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,932.328);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,659.255);
                                            robot.beep((0)*beat,0.0);
                                            //8
                                            robot.beep((1.0/3.0)*beat,698.456);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,523.251);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,698.456);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,880.000);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,1046.50);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((5.0/6.0)*beat,659.255);
                                            robot.beep((1.0/6.0)*beat,0.0);
                                            //9
                                            robot.beep((1.0/3.0)*beat,698.456);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,523.251);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,698.456);
                                            robot.beep((1.0/3.0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,880.000);
                                            robot.beep((0)*beat,0.0);
                                            robot.beep((1.0/3.0)*beat,1046.50);
                                            robot.beep((2.0/3.0)*beat,0.0);
                                            robot.beep((5.0/6.0)*beat,659.255);
                                            robot.beep((1.0/6.0)*beat,0.0);
                                            //10
                                            robot.beep((2)*beat,698.456);
                                            }
                                            void print()
                                            {
                                            for(int i=0; i < 20; i++)
                                            {
                                            switch(playlist[i])
                                            {
                                            case 0:
                                            cout << "Hotel California" << endl;
                                            break;
                                            case 1:
                                            cout << "Ode to Joy" << endl;
                                            break;
                                            case 2:
                                            cout << "A Blimpie Original" << endl;
                                            break;
                                            case 3:
                                            cout << "Twinkle, Twinkle, Little Star" << endl; 
                                            break;
                                            case 4: 
                                            cout << "Fight On" << endl;
                                            break;
                                            }
                                            }
                                            
                                            }
                                            int start()
                                            {
                                            for(int i=0; i < 20; i++)
                                            {
                                            if(playlist[i] == 0)
                                            {
                                            hotelCalifornia();
                                            }
                                            else if(playlist[i] == 1)
                                            {
                                            odeToJoy();
                                            }
                                            else if(playlist[i] == 2)
                                            {
                                            randomSong();
                                            }
                                            else if(playlist[i] == 3)
                                            {
                                            twinkle();
                                            }
                                            else if(playlist[i] == 4)
                                            {
                                            fightOn();
                                            }
                                            }
                                            }
                                            void Ena()
                                            {
                                            int n=1;
                                            if (n<=4)
                                            {
                                            robot.turnRight(2,1.25);
                                            robot.forward(10,2);
                                            robot.turnRight(2,1.25);
                                            robot.forward(10,2);
                                            robot.turnRight(2,1.25);
                                            robot.forward(10,2);
                                            robot.turnRight(2,1.25);
                                            robot.forward(10,2);
                                            robot.turnRight(2,1.25);
                                            robot.forward(10,2);
                                            }
                                            
                                            }
                                            void Basil()
                                            {
                                            int counter = 0;
                                            while(counter < 4)
                                            {
                                            robot.forward(1,0.05);
                                            robot.turnLeft(1,.733/9);
                                            robot.forward(1,0.05);
                                            robot.turnLeft(1,.733);
                                            robot.forward(1,2);
                                            //Crossed page
                                            robot.turnRight(1,.733);
                                            robot.forward(1,0.05);
                                            robot.turnRight(1,.733/9);
                                            robot.forward(1,0.05);
                                            robot.turnRight(1,.733);
                                            robot.forward(1,2);
                                            //Crossed page
                                            robot.turnRight(1,.733);
                                            robot.forward(1,0.05);
                                            robot.turnRight(1,.733/9);
                                            robot.forward(1,0.05);
                                            robot.turnRight(1,.733);
                                            robot.forward(1,2);
                                            //Crossed page
                                            robot.turnLeft(1,.733);
                                            counter ++;
                                            }
                                            }
                                            void Ryan()
                                            {
                                            for (int i=0; i<3; i++) {
                                            if (robot.getObstacle("center")<7000) {
                                            robot.motors((robot.getLight()%10),1);
                                            wait(3);
                                            robot.forward(1,1);
                                            }
                                            else {
                                            robot.beep(1.0,300);
                                            robot.beep(1.0,300);
                                            }
                                            
                                            }
                                            }
                                            void Victoria()
                                            {
                                            robot.motors(0,1);
                                            wait(4);
                                            robot.forward(1,1);
                                            robot.turnLeft(1,.65);
                                            robot.forward(1,1);
                                            robot.motors(0,1);
                                            wait(4);
                                            robot.stop();
                                            }
                                            int draw()
                                            {
                                            for(int i = 0; i < 4; i++)
                                            {
                                            switch(drawing[i])
                                            {
                                            case 0:
                                            Ena();
                                            break;
                                            case 1:
                                            Basil();
                                            break;
                                            case 2:
                                            Ryan();
                                            break;
                                            case 3:
                                            Victoria();
                                            break;
                                            default:
                                            break;
                                            }
                                            }
                                            }
                                            void dprint()
                                            {
                                            for(int i=0; i < 4; i++)
                                            {
                                            switch(drawing[i]){
                                            
                                            case 0:
                                            cout << "Ena's Drawing" << endl;
                                            break;
                                            case 1:
                                            cout << "My Drawing" << endl;
                                            break;
                                            case 2:
                                            cout << "Ryan's Drawing" << endl;
                                            break;
                                            case 3:
                                            cout << "Victoria's Drawing" << endl;
                                            break;
                                            default:
                                            break;
                                            }
                                            }
                                            }
                                            
                                            
                                            
                                            int main(int argc, char ** argv)
                                            {
                                            connect("/dev/tty.Fluke2-01C7-Fluke2");
                                            int drawplay;
                                            cout << "Choose 1 to draw, 2 to sing" << endl;
                                            cin >> drawplay;
                                            if(drawplay == 1)
                                            {
                                            cout << "0 for Ena's Drawing, 1 for My drawing, 2 for Ryan's Drawing, and 3 For Victoria's Drawing" << endl;
                                            cout << "Choose the order you want the drawings to be made, using the above numbers. Press enter after each input" << endl;
                                            for(int i = 0; i < 4; i++)
                                            {
                                            int dchoice;
                                            cin >> dchoice;
                                            drawing[i] = dchoice;
                                            }
                                            dprint();
                                            draw();
                                            }
                                            else if(drawplay == 2)
                                            {
                                            cout << "0 for Hotel California, 1 for Ode to Joy, 3 to have Blimpie write a song for you, 4 for Twinkle, Twinkle, Little Star, and 5 for Fight On" << endl;
                                            cout << "Choose the order you want the songs to play, using the above numbers. Press enter after each input" << endl;
                                            for(int i = 0; i < 20; i++)
                                            {
                                            int choice;
                                            cin >> choice;
                                            playlist[i] = choice;
                                            } // For user inputs, asked Ryan for help
                                            print();
                                            start();
                                            
                                            }
                                            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