
#include<iostream>
#include<conio.h>
#include<dos.h>
#include <windows.h>
#include <time.h>
//#define SCREEN_WIDTH 90
//#define SCREEN_HEIGHT 26
#define WIN_WIDTH 70
#define T1POS 15
#define T2POS 30
#define T3POS 45
#define DISKS 5
using namespace std;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
int towers[3][DISKS];
int towerTop[3] = {DISKS-1,-1,-1};
int tries = 0;
int score = 0;
void gotoxy(int x, int y){
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console, CursorPosition);
}
void setcursor(bool visible, DWORD size) {
if(size == 0)
size = 20;
CONSOLE_CURSOR_INFO lpCursor;
lpCursor.bVisible = visible;
lpCursor.dwSize = size;
SetConsoleCursorInfo(console,&lpCursor);
}
void updateScore(){
gotoxy(WIN_WIDTH + 7, 5);cout<<"Tries: "<<tries<<endl;
}
void instructions(){
system("cls");
cout<<"Instructions";
cout<<"\n----------------";
cout<<"\n Shift Disks from Tower 1 to Tower 3. ";
cout<<"\n You can not place large disk on small disk";
cout<<"\n Towers are Numbered as 1,2 and 3";
cout<<"\n\nPress any key to go back to menu";
getch();
}
void drawTile(int tower, int tileNo, int y){
int x;
if( tower == 1 ) x = T1POS;
else if( tower == 2 ) x = T2POS;
else if( tower == 3 ) x = T3POS;
x -= tileNo;
for(int j=0; j<((tileNo)*2)-1; j++){
gotoxy(x,y);
cout<<"±";
x++;
}
}
void drawTower(int tower){
int x;
int y = 9;
gotoxy(10, 10); cout<<"==========";
gotoxy(25, 10); cout<<"==========";
gotoxy(40, 10); cout<<"==========";
gotoxy(15, 11); cout<<"1";
gotoxy(30, 11); cout<<"2";
gotoxy(45, 11); cout<<"3";
for(int i=0; i<5; i++){
drawTile(tower, towers[tower-1][i], y);
y--;
}
}
int isEmpty(int towerNo){
for(int i=0; i<DISKS; i++)
if( towers[towerNo][i] != 0 )
return 0;
return 1;
}
int validate(int from, int to){
if( !isEmpty(to) ){
if( towers[from][towerTop[from]] < towers[to][towerTop[to]] )
return 1;
else
return 0;
}
return 1;
}
int move(int from, int to){
if( isEmpty(from) ) return 0;
if( validate(from, to) ){
if( towers[from][towerTop[from]] != 0 ){
towerTop[to]++;
towers[to][towerTop[to]] = towers[from][towerTop[from]];
towers[from][towerTop[from]] = 0;
towerTop[from]--;
return 1;
}
}
return 0;
}
int win(){
for(int i=0; i<DISKS; i++)
if( towers[2][i] != DISKS-i )
return 0;
return 1;
}
void play(){
int from, to;
for(int i=0; i<DISKS; i++)
towers[0][i] = DISKS-i;
for(int i=0; i<DISKS; i++)
towers[1][i] = 0;
for(int i=0; i<DISKS; i++)
towers[2][i] = 0;
do{
system("cls");
cout<<"============================================================"<<endl;
cout<<" TOWER OF HANOI "<<endl;
cout<<"============================================================"<<endl<<endl;
drawTower(1);
drawTower(2);
drawTower(3);
if( win() ){
system("cls");
cout<<"============================================================"<<endl;
cout<<" YOU WIN "<<endl;
cout<<"============================================================"<<endl;
cout<<endl<<endl<<endl;
cout<<"Press any key to go back to menu...";
getch();
break;
}
gotoxy(10,15);
cout<<"From (Values: 1,2,3): ";
cin>>from;
gotoxy(10,16);
cout<<"To (Values: 1,2,3): ";
cin>>to;
if( to < 1 || to > 3 ) continue;
if( from < 1 || from > 3 ) continue;
if( from == to ) continue;
from--;
to--;
move(from, to);
if(kbhit()){
char ch = getch();
if( ch=='a' || ch=='A' ){
}
if( ch=='d' || ch=='D' ){
}
if(ch==27){
break;
}
}
}while(1);
}
int main()
{
setcursor(0,0);
srand( (unsigned)time(NULL));
do{
system("cls");
gotoxy(10,5); cout<<" -------------------------- ";
gotoxy(10,6); cout<<" | Tower of Hanoi | ";
gotoxy(10,7); cout<<" --------------------------";
gotoxy(10,9); cout<<"1. Start Game";
gotoxy(10,10); cout<<"2. Instructions";
gotoxy(10,11); cout<<"3. Quit";
gotoxy(10,13); cout<<"Select option: ";
char op = getche();
if( op=='1') play();
else if( op=='2') instructions();
else if( op=='3') exit(0);
}while(1);
return 0;
}


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- #include <iostream>#include <iomanip>#include <cmath>using namespace std; #define PROPERTY_TAX_RATE_PER_YEAR 1.25#define COST_OF_UTILITIES_PER_MONTH 300.00#define COST_OF_INSURANCE_PER_YEAR 550.00 void inputData(double& sellingPrice, double& interestRate, int& durationOfLoan); void handleAllComputations(double sellingPrice,double interestRate,int durationOfLoan,double downPaymentRate,double& downPayment,double& amountOfLoan,double& mortgagePayment,double& propertyTax,double& costOfInsurance,double& totalMonthlyHouseCost); double calculateDownPayment(double sellingPrice, double downPaymentRate);double calculateAmountOfLoan(double sellingPrice, double downPayment);double calculateMortgagePayment(double amountOfLoan,double interestRate,int durationOfLoan); void outputResults(double sellingPrice,double downPayment,double amountOfLoan,double interestRate,int durationOfLoan,double mortgagePayment,double propertyTax,double…arrow_forward#include <iostream> #include <cmath> #include <iomanip> using namespace std; int calc_qty(int qty); void receipt( int qty, int qty2); int calc_qty(int qty); void coffee_size(int qty, int size, int choice, int qty2); void slices(); void beanounces(); int main() { int qty = 0, order = 0, size = 0, qty2 = 0; receipt (qty,qty2); calc_qty (qty); do { //displays the menu cout<<" Please select an item on the menu you would like to buy."<<endl; cout<<"Enter 1 for Coffee\n"<<"Enter 2 for cheese cake\n"<<"Enter 3 for coffee beens\n"<<endl; cin>>choice; } switch (choice) { case 1: coffee_size(qty, size, order, qty2); break; case 2: slices(); break; case 3: beanounces(); break; case 4: cout<<"Enjoy your day"<<endl;…arrow_forward#include <xc.h> void ____(void); void main (void) { TRISDbits.TRISD0 = ____;TRISDbits.TRISD1 = 0;TRISDbits.TRISD2 = ____;TRISDbits.TRISD3 = 0; ____ = 0; PORTDbits.RD0 = ____; PORTDbits.RD1 = 0; if(____ == 0)fail(); PORTDbits.RD0 = ____; PORTDbits.RD1 = 1; if(PORTDbits.RD2 == 0)fail(); ____ = 1; PORTDbits.RD1 = 0; if(____ == 0)____; PORTDbits.RD0 = ____; PORTDbits.RD1 = ____; if(PORTDbits.RD2 == ____)fail(); while(1) { PORTDbits.RD3 = 1; PORTDbits.RD4 = 0; } } void fail(void) { while(1) { PORTDbits.RD3 = ____; PORTDbits.RD4 = ____; } }arrow_forward
- This is a main module. w7_main Module (supplied) Do not modify this module! Look at the code and make sure you understand it. // Workshop 7 // Version: 1.0 // Author: Asam Gulaid // Description: // This file tests your workshop 7 ///////////////////////////////////////////// #include<iostream> #include "Minister.h" #include "Minister.h" // intentional #include "MemberParliament.h" #include "MemberParliament.h" // intentional using namespace std; using namespace sdds; void printHeader(const char* title) { char oldFill = cout.fill('-'); cout.width(62); cout << "" << endl; cout << "|> " << title << endl; cout.fill('-'); cout.width(62); cout << "" << endl; cout.fill(oldFill); } void newElections(Minister& aMinister, const char* district, const char* newPM, double year) { aMinister.NewDistrict(district); aMinister.changePM(newPM); aMinister.assumeOffice(year); cout << "Status of New Election " << aMinister << endl…arrow_forward#include <iostream>#include <pthread.h>#include <stdlib.h> #define TOTAL_THREADS 4 int count;pthread_mutex_t the_mutex; // phread mutex variable - initialize here if using the initializer macro void* myFunction(void* arg){int actual_arg = *((int*) arg);for(unsigned int i = 0; i < 10; ++i) {// TODO:// Use a Pthread mutex to control// access to the critical region. // Beginning of the critical regioncount++;std::cout << "Thread #" << actual_arg << " count = " << count << std::endl; // End of the critical region// TODO:// Relinquish access to the Pthread mutex// since critical region is complete. // Random wait - This code is just to ensure that the threads// show data sharing problemsint max = rand() % 100000;for (int x = 0; x < max; x++);// End of random wait code}pthread_exit(NULL);} int main(){int rc[TOTAL_THREADS];pthread_t ids[TOTAL_THREADS];int args[TOTAL_THREADS];// TODO: Initialize the pthread mutex here if using the…arrow_forwardNeed help with the questions provided below.arrow_forward
- code is still not working!! please help me ! idk why it wont work. I was following directions as given. #include #include #include #include #include #pragma pack(push, 1) typedef struct { int8_tjump_to_bootstrap[3]; int8_toem_id[8]; uint16_tbytes_per_sector; uint8_tsectors_per_cluster; uint16_treserved_sectors; uint8_tfat_copies; uint16_troot_dir_entries; uint16_ttotal_sectors; uint8_tmedia_descriptor_type; uint16_tsectors_per_fat; uint16_tsectors_per_track; uint16_theads; uint32_thidden_sectors; uint32_ttotal_sectors2; uint8_tdrive_index; uint8_t_stuff; uint8_tsignature; uint32_tid; int8_tlabel[11]; int8_ttype[8]; int8_t_more_stuff[448]; uint16_tsig; } boot_t; typedef struct { int8_tfilename[8]; int8_textension[3]; int8_tattributes; int8_t_reserved[10]; uint16_tupdate_time; uint16_tupdate_date; uint16_tstarting_cluster; uint32_tfile_size; } dir_entry_t; #pragma pack(pop) void readSector(FILE *disk, uint32_t sectorNumber, uint8_t *buffer, uint16_t bytesPerSector) { if…arrow_forwardAll files are included below, seperated by the dashes. "----" //driver.cpp #include <iostream> #include <string> #include "stackLL.h" #include "queueLL.h" #include "priorityQueueLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLLstk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout<<"Popping: "<<stk.pop() <<endl; cout<<"Popping: "<<stk.pop() <<endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout<<"Popping: "<<stk.pop() <<endl; } // output order: 11,2,23,19,17,3,7,13,5 stackLLstkx; stkx.push(5); stkx.push(10); stkx.push(15); stkx.push(20); stkx.push(25); stkx.push(30); stkx.insertAt(-100, 3); stkx.insertAt(-200, 7); stkx.insertAt(-300, 0); //output order: -300,30,25,20,-100,15,10,5,-200 while( ! stkx.empty() ) cout<<"Popping: "<<stkx.pop() <<endl; ///////////////////////////////////////…arrow_forwardPlease answer in C++arrow_forward
- It is customary to start the name of an accessor with ____ and the name of a mutator with _____arrow_forwardpython >>> feathered_pets=["canary", "parrot", "budgie", "hawk"]>>> furry_pets=["dog", "cat", "ferret", "hamster", "bunny"]>>> all_pets=furry_pets+feathered_pets what will give me the result ["parrot", "canary", "bunny"]arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





