SlideShare a Scribd company logo
1 of 3
Designing the Application
  1. Start Borland C++ Builder with the default form
  2. Change the Caption of the form to Traffic Light
  3. Change its BorderStyle property to bsDialog
  4. Change its dimensions to Height = 256 and Width = 112
  5. From the Statndard tab of the Component Palette, double-click the Panel control
  6. Change the properties of the panel as follows:
       BevelInner = bvNone
       BevelOuter = bvLowered
       BevelWidth = 5
       Caption     = Empty
       Color      = clBlack
       Height      = 209
       Left        = 17
       Top         =8
       Width       = 81
  7. While the panel is still selected on the form, from the Additional tab of the Component
     Palette, double-click the Shape control
  8. Change the following properties for the new Shape:
       Brush: Color = clGray
       Brush: Style = bsSolid
       Height          = 65
       Left             =8
       Top             =8
       Width            = 65
  9. On the panel, click the newly added Shape to make sure it is selected. Press Ctrl + C to
     copy it to the clipboard
  10. Click anywhere on the panel to select it.
  11. Press Ctrl + V to paste the Shape
  12. While the new Shape is still selected, change its Left value to 8 and its Top value to 72
  13. Click an empty area on the panel to select it and press Ctrl + V.
  14. While the new shape is still selected, change its Left value to 8 and its Top value to 136
  15. Click the panel on the form and ress Ctrl + V again
  16. Change the properties of the new shape as follows:
        Brush: Color = clRed
        Height        = 57
        Left          =8
        Name          = shpRed
        Shape         = stCircle
        Top           = 12
  17. On the form, click the red circle and press Ctrl + C. Then press Ctrl + V to add a new Shape
  18. Change its properties as follows:
        Brush: Color = clSilver
Height         = 57
        Left           =8
        Name            = shpYellow
        Shape            = stCircle
        Top              = 76
  19. On the form, click the Panel and press Ctrl + V
  20. Change the properties of the new Shape to:
        Brush: Color = clSilver
        Height        = 57
        Left          =8
        Name         = shpGreen
        Shape         = stCircle
        Top           = 140
  21. From the System tab of the Component Palette, double-click Timer

Coding the Application
  1. On the Object Inspector, click the Events tab
  2. Although the dialog box will be equipped with the system Close button, we should provide
     our own meand of closing the application.
     On the form, click the red circle.
  3. Press and hold Shift, then click the other two circles
  4. On the Object Inspector, double-click the empty area on the right side of OnMouseDown
  5. Change the event as follows:


      //---------------------------------------------------------------------------
      void __fastcall TForm1::shpGreenMouseDown(TObject *Sender,
            TMouseButton Button, TShiftState Shift, int X, int Y)
      {
          Close();
      }
      //---------------------------------------------------------------------------

  6. Press F12 to display the form.
  7. Double-click the Timer on the form to access its OnTimer event
  8. Change its code as follows:


      //---------------------------------------------------------------------------
      void __fastcall TForm1::Timer1Timer(TObject *Sender)
      {
          // If the current color is red
          if( shpRed->Brush->Color == clRed )
          {
              // Change the color to green
              Timer1->Interval        = 3500;
              shpRed->Brush->Color    = clSilver;
              shpYellow->Brush->Color = clSilver;
              shpGreen->Brush->Color = clGreen;
}
        // But if the color is green
        else if( shpGreen->Brush->Color == clGreen )
        {
            // Change the color to yellow
            Timer1->Interval         = 2000;
            shpRed->Brush->Color     = clSilver;
            shpYellow->Brush->Color = clYellow;
            shpGreen->Brush->Color = clSilver;
        }
        // Otherwise, if the color is yellow
        else // if(shpYellow->Brush->Color == clYellow
        {
            // Change the color to red
            Timer1->Interval         = 5000;
            shpRed->Brush->Color     = clRed;
            shpYellow->Brush->Color = clSilver;
            shpGreen->Brush->Color = clSilver;
        }
   }
   //---------------------------------------------------------------------------

9. Test your program.

More Related Content

What's hot

Validating and Sanitizing User Data
Validating and Sanitizing  User DataValidating and Sanitizing  User Data
Validating and Sanitizing User Datazakieh alizadeh
 
LUDO BOARD GAME OPENGL COMPUTER GRAPHICS
LUDO BOARD GAME OPENGL COMPUTER GRAPHICSLUDO BOARD GAME OPENGL COMPUTER GRAPHICS
LUDO BOARD GAME OPENGL COMPUTER GRAPHICSRAJEEV KUMAR SINGH
 
James Webb telescope introduction presentation
James Webb telescope introduction presentationJames Webb telescope introduction presentation
James Webb telescope introduction presentationStinson
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Presentation On Android
Presentation On AndroidPresentation On Android
Presentation On AndroidTeachMission
 
Seminar on mobile application development with android
Seminar on mobile application development with androidSeminar on mobile application development with android
Seminar on mobile application development with androidNoor Mohammed Anik
 
ISRO & It's Achivements
ISRO & It's AchivementsISRO & It's Achivements
ISRO & It's AchivementsGOURAV BISEN
 
Indian space research organisation, (ISRO) 8102408728 call me
Indian space research organisation, (ISRO) 8102408728 call meIndian space research organisation, (ISRO) 8102408728 call me
Indian space research organisation, (ISRO) 8102408728 call meamit_shanu
 
Snake game implementation in c
Snake game implementation in cSnake game implementation in c
Snake game implementation in cUpendra Sengar
 
2nd PUC computer science chapter 6 oop concept
2nd PUC computer science chapter 6   oop concept2nd PUC computer science chapter 6   oop concept
2nd PUC computer science chapter 6 oop conceptAahwini Esware gowda
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmNeha Kaurav
 
Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentationPrionto Abdullah
 

What's hot (20)

Validating and Sanitizing User Data
Validating and Sanitizing  User DataValidating and Sanitizing  User Data
Validating and Sanitizing User Data
 
Gaming Console
Gaming Console Gaming Console
Gaming Console
 
LUDO BOARD GAME OPENGL COMPUTER GRAPHICS
LUDO BOARD GAME OPENGL COMPUTER GRAPHICSLUDO BOARD GAME OPENGL COMPUTER GRAPHICS
LUDO BOARD GAME OPENGL COMPUTER GRAPHICS
 
James Webb telescope introduction presentation
James Webb telescope introduction presentationJames Webb telescope introduction presentation
James Webb telescope introduction presentation
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Snap Lens Tutorial
Snap Lens TutorialSnap Lens Tutorial
Snap Lens Tutorial
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Presentation On Android
Presentation On AndroidPresentation On Android
Presentation On Android
 
Seminar on mobile application development with android
Seminar on mobile application development with androidSeminar on mobile application development with android
Seminar on mobile application development with android
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
 
ISRO & It's Achivements
ISRO & It's AchivementsISRO & It's Achivements
ISRO & It's Achivements
 
Rasberry pi
 Rasberry pi Rasberry pi
Rasberry pi
 
space technology
space technologyspace technology
space technology
 
Indian space research organisation, (ISRO) 8102408728 call me
Indian space research organisation, (ISRO) 8102408728 call meIndian space research organisation, (ISRO) 8102408728 call me
Indian space research organisation, (ISRO) 8102408728 call me
 
Astrophysics
AstrophysicsAstrophysics
Astrophysics
 
Snake game implementation in c
Snake game implementation in cSnake game implementation in c
Snake game implementation in c
 
2nd PUC computer science chapter 6 oop concept
2nd PUC computer science chapter 6   oop concept2nd PUC computer science chapter 6   oop concept
2nd PUC computer science chapter 6 oop concept
 
Project synopsis on java game development
Project synopsis on java game developmentProject synopsis on java game development
Project synopsis on java game development
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentation
 

Viewers also liked

Logika dan Algoritma pemrograman
Logika dan Algoritma pemrogramanLogika dan Algoritma pemrograman
Logika dan Algoritma pemrogramanArif Huda
 
Pertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CPertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CNurdin Al-Azies
 
Pertemuan 6 Struktur Data, Algoritma dan Pemrograman
Pertemuan 6 Struktur Data, Algoritma dan PemrogramanPertemuan 6 Struktur Data, Algoritma dan Pemrograman
Pertemuan 6 Struktur Data, Algoritma dan PemrogramanPrasetyo Adi
 
Bahasa Pemrograman C++
Bahasa Pemrograman C++Bahasa Pemrograman C++
Bahasa Pemrograman C++Rangga Ananto
 
Student result mamagement
Student result mamagementStudent result mamagement
Student result mamagementMickey
 

Viewers also liked (8)

Logika dan Algoritma pemrograman
Logika dan Algoritma pemrogramanLogika dan Algoritma pemrograman
Logika dan Algoritma pemrograman
 
Pertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CPertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman C
 
Pertemuan 6 Struktur Data, Algoritma dan Pemrograman
Pertemuan 6 Struktur Data, Algoritma dan PemrogramanPertemuan 6 Struktur Data, Algoritma dan Pemrograman
Pertemuan 6 Struktur Data, Algoritma dan Pemrograman
 
Bahasa Pemrograman C++
Bahasa Pemrograman C++Bahasa Pemrograman C++
Bahasa Pemrograman C++
 
Relasi dan fungsi
Relasi dan fungsiRelasi dan fungsi
Relasi dan fungsi
 
Students report card for C++ project..
Students report card for C++ project..Students report card for C++ project..
Students report card for C++ project..
 
Student result mamagement
Student result mamagementStudent result mamagement
Student result mamagement
 
Deep C
Deep CDeep C
Deep C
 

Similar to C++ program for TRAFFIC LIGHT

Auto cad workbook2d hartnell college engineering technology
Auto cad workbook2d   hartnell college engineering technologyAuto cad workbook2d   hartnell college engineering technology
Auto cad workbook2d hartnell college engineering technologyAlFakir Fikri AlTakiri
 
Corel Draw Beginner Tutorial: How to Make a New Product Flyer
Corel Draw Beginner Tutorial: How to Make a New Product FlyerCorel Draw Beginner Tutorial: How to Make a New Product Flyer
Corel Draw Beginner Tutorial: How to Make a New Product FlyerFlyer Tutor
 
Solidworks apple mouse Design
Solidworks apple mouse DesignSolidworks apple mouse Design
Solidworks apple mouse DesignRa'uf Tailony
 
Zmorph Dual Head User Manual for Printing
Zmorph Dual Head User Manual for PrintingZmorph Dual Head User Manual for Printing
Zmorph Dual Head User Manual for PrintingRyan Dunn
 
Calculator Manipulation.pptx
Calculator Manipulation.pptxCalculator Manipulation.pptx
Calculator Manipulation.pptxfroilandoblon1
 
Solid works lab manual including auto cad
Solid works lab manual including auto cadSolid works lab manual including auto cad
Solid works lab manual including auto cadPUDOTATHARUN
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docxmayank272369
 

Similar to C++ program for TRAFFIC LIGHT (20)

Fx plus ch_intro
Fx plus ch_introFx plus ch_intro
Fx plus ch_intro
 
Maya
MayaMaya
Maya
 
Maya
MayaMaya
Maya
 
Sap arch
Sap archSap arch
Sap arch
 
Auto cad workbook2d hartnell college engineering technology
Auto cad workbook2d   hartnell college engineering technologyAuto cad workbook2d   hartnell college engineering technology
Auto cad workbook2d hartnell college engineering technology
 
Corel Draw Beginner Tutorial: How to Make a New Product Flyer
Corel Draw Beginner Tutorial: How to Make a New Product FlyerCorel Draw Beginner Tutorial: How to Make a New Product Flyer
Corel Draw Beginner Tutorial: How to Make a New Product Flyer
 
Solidworks apple mouse Design
Solidworks apple mouse DesignSolidworks apple mouse Design
Solidworks apple mouse Design
 
3d Model of “Bearing”
3d Model of “Bearing”3d Model of “Bearing”
3d Model of “Bearing”
 
Tutorial ic design
Tutorial ic designTutorial ic design
Tutorial ic design
 
Zmorph Dual Head User Manual for Printing
Zmorph Dual Head User Manual for PrintingZmorph Dual Head User Manual for Printing
Zmorph Dual Head User Manual for Printing
 
Phoenics tutorial
Phoenics tutorialPhoenics tutorial
Phoenics tutorial
 
Spl book salution
Spl book salutionSpl book salution
Spl book salution
 
Calculator Manipulation.pptx
Calculator Manipulation.pptxCalculator Manipulation.pptx
Calculator Manipulation.pptx
 
Solid works lab manual including auto cad
Solid works lab manual including auto cadSolid works lab manual including auto cad
Solid works lab manual including auto cad
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
 
Ansys iges tutorial
Ansys iges tutorialAnsys iges tutorial
Ansys iges tutorial
 
New manual
New manualNew manual
New manual
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 

C++ program for TRAFFIC LIGHT

  • 1. Designing the Application 1. Start Borland C++ Builder with the default form 2. Change the Caption of the form to Traffic Light 3. Change its BorderStyle property to bsDialog 4. Change its dimensions to Height = 256 and Width = 112 5. From the Statndard tab of the Component Palette, double-click the Panel control 6. Change the properties of the panel as follows: BevelInner = bvNone BevelOuter = bvLowered BevelWidth = 5 Caption = Empty Color = clBlack Height = 209 Left = 17 Top =8 Width = 81 7. While the panel is still selected on the form, from the Additional tab of the Component Palette, double-click the Shape control 8. Change the following properties for the new Shape: Brush: Color = clGray Brush: Style = bsSolid Height = 65 Left =8 Top =8 Width = 65 9. On the panel, click the newly added Shape to make sure it is selected. Press Ctrl + C to copy it to the clipboard 10. Click anywhere on the panel to select it. 11. Press Ctrl + V to paste the Shape 12. While the new Shape is still selected, change its Left value to 8 and its Top value to 72 13. Click an empty area on the panel to select it and press Ctrl + V. 14. While the new shape is still selected, change its Left value to 8 and its Top value to 136 15. Click the panel on the form and ress Ctrl + V again 16. Change the properties of the new shape as follows: Brush: Color = clRed Height = 57 Left =8 Name = shpRed Shape = stCircle Top = 12 17. On the form, click the red circle and press Ctrl + C. Then press Ctrl + V to add a new Shape 18. Change its properties as follows: Brush: Color = clSilver
  • 2. Height = 57 Left =8 Name = shpYellow Shape = stCircle Top = 76 19. On the form, click the Panel and press Ctrl + V 20. Change the properties of the new Shape to: Brush: Color = clSilver Height = 57 Left =8 Name = shpGreen Shape = stCircle Top = 140 21. From the System tab of the Component Palette, double-click Timer Coding the Application 1. On the Object Inspector, click the Events tab 2. Although the dialog box will be equipped with the system Close button, we should provide our own meand of closing the application. On the form, click the red circle. 3. Press and hold Shift, then click the other two circles 4. On the Object Inspector, double-click the empty area on the right side of OnMouseDown 5. Change the event as follows: //--------------------------------------------------------------------------- void __fastcall TForm1::shpGreenMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Close(); } //--------------------------------------------------------------------------- 6. Press F12 to display the form. 7. Double-click the Timer on the form to access its OnTimer event 8. Change its code as follows: //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { // If the current color is red if( shpRed->Brush->Color == clRed ) { // Change the color to green Timer1->Interval = 3500; shpRed->Brush->Color = clSilver; shpYellow->Brush->Color = clSilver; shpGreen->Brush->Color = clGreen;
  • 3. } // But if the color is green else if( shpGreen->Brush->Color == clGreen ) { // Change the color to yellow Timer1->Interval = 2000; shpRed->Brush->Color = clSilver; shpYellow->Brush->Color = clYellow; shpGreen->Brush->Color = clSilver; } // Otherwise, if the color is yellow else // if(shpYellow->Brush->Color == clYellow { // Change the color to red Timer1->Interval = 5000; shpRed->Brush->Color = clRed; shpYellow->Brush->Color = clSilver; shpGreen->Brush->Color = clSilver; } } //--------------------------------------------------------------------------- 9. Test your program.