Question

ELEN 1301-01 Programming Assignment #11 Due date: November 11, 2015. Wednesday (At the beginning of class.)...

ELEN 1301-01 Programming Assignment #11

Due date: November 11, 2015. Wednesday (At the beginning of class.)

Please submit:
1. Flowchart of your program. (4 points) 2. Printout of your C++ program with a heading comment (Do not forget to

add comments within your program). (4 points)

3. Copy of a screenshot after your program is executed. (2 points)

4. You must use a two dimensional array in order to receive any credit.

/*

   ELEN 1301-01          Programming Assignment #11.

   Name        : Your name.

   Student ID : Your student ID #.

   Due date    : November 11, 2015

Purpose of the program:

Create a program that places mines in the 20 X 20 field and display it

with the number of mines in the 8 surrounding areas.

Section 1 Set a random number seed with 2 followed by the last 3

digits of your student ID.

Section 2 Place mines in your field. Around 10 % of the field should

be mines.

Section 3 Find the number of mines in the 8 surrounding areas.

Output examples :

Section 4 Display the mine field. Mine should be represented by “#”

and other areas should be shown with the number of mines nearby.

*/

i just need the program written that accomplishes what is stated above in xcode or microsoft visual studio in C++ language.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

this may help you

#include<iostream>
#include<time.h>
#include<ctime>
#include<fstream>;
#include<cstdlib>
using namespace std;

//prototypes of functions
void mines(int a[][8],int size);
void numbers(int array[][8],int size);
void board(char array2[][8],int size);
int axis(int array[][8],char array2[][8],int array3[][8],int array4[][8],int size);
void highscore(int & b);
void help();

//help function
void help(){
cout<<endl;
cout<<"Welcome to Minesweeper Game Made by Dr.Death"<<endl;
cout<<"At any given Time you can press D for Replay or E for Exiting the game"<<endl;
cout<<"1.during play use left and right click option for replay and Exit "<<endl;
cout<<"2.when u see 0 revealed then u can open its neighboring cell without any risk"<<endl;
cout<<"3.only 10 Flags are available.Flags are your hint that mine is there "<<endl;
cout<<"4.when you will open all the numbers without mine.you will win "<<endl;
cout<<"5.To unflag a flag jump to same cell and press r"<<endl;
}



//Placing mines
void mines(int a[][8],int size){
for(int i=0;i<10;i++)
{
int row=rand()%size;
int col=rand()%size;
   if(a[row][col]==9)
   { i--;
}
a[row][col]=9;
}
}

//placing numbers
void numbers(int array[][8],int size){
for(int j=0;j<size;j++){
for(int k=0;k<size;k++){
  

   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j-1][k-1]==9){
     array[j][k]++;
    }
   }
   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j-1][k]==9){
     array[j][k]++;
    }
   }

   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j-1][k+1]==9){
     array[j][k]++;
    }
   }

   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j][k-1]==9){
     array[j][k]++;
    }
  
   }

   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j][k+1]==9){
     array[j][k]++;
    }
   }

   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j+1][k-1]==9){
     array[j][k]++;
    }
   }

   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j+1][k]==9){
     array[j][k]++;
    }
   }
   if(array[j][k]!=9&&k>0&&k<7){
    if(array[j+1][k+1]==9){
     array[j][k]++;
    }
   }
}
}
for(j=0;j<size;j++){
for(int k=0;k<size;k++){
  
   if((array[j][k]!=9)&&(k==0)){
    if(array[j-1][k]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==0)){
    if(array[j-1][k+1]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==0)){
    if(array[j][k+1]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==0)){
    if(array[j+1][k]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==0)){
    if(array[j+1][k+1]==9){
     array[j][k]++;
    }
   }

  
  
  
   if((array[j][k]!=9)&&(k==7)){
    if(array[j-1][k-1]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==7)){
    if(array[j-1][k]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==7)){
    if(array[j][k-1]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==7)){
    if(array[j+1][k-1]==9){
     array[j][k]++;
    }
   }
  
   if((array[j][k]!=9)&&(k==7)){
    if(array[j+1][k]==9){
     array[j][k]++;
    }
   }

}
}

}

//setting board
void board(char array2[][8],int size){

char a=178;
for(int m=0;m<size;m++){
for(int j=0;j<size;j++){
  
   array2[m][j]=a;
  
}
}
}

//moving in board.this is the main function
int axis(int array[][8],char array2[][8],int array3[][8],int array4[][8],int size){
int counterf=0;
int total=0; int totalf=0;
int set=0;
char a=178;
char b=179;
int urow;
int ucol;
char o;
char temp;
int count=0;
for(int x=0;x<8;x++){
   for(int y=0;y<8;y++){
    if(array[x][y]!=9){
    totalf=totalf+array[x][y];
    }
   }
}

int time=0;
int set2;
for(int i=1;i>0;i++)
{
count++;
if(i>0){
  
   time=clock();
   if(time/1000>999) // minesweeper has three digit timer
   {
    time=999999;
   }
   cout<<"time elasped : "<<time/1000<<" seconds"<<endl;
   cout<<"total : "<<total<<endl;
   cout<<"Enter row no. : ";
cin>>urow;
cout<<"Enter coloumn no. : ";
cin>>ucol;
cout<<"Enter right click or left click : ";
cin>>o;
urow=urow-1;
ucol=ucol-1;
if(o=='D'||o=='d'){
   cout<<"do you really want to restart game(press 1 for yes or any other key for no) ";
   cin>>set2;
    if(set2==1){
     break;
    }
    if(set2==2){
     cout<<" ";
     continue;
    }
}
if(o=='e'||o=='E'){
   cout<<"do you really want to Exit from game(press 1 for yes or anyother key for no) ";
   cin>>set2;
    if(set2==1){
     cout<<"Thanks for Playing Alah Hafiz"<<endl;
    system("PAUSE");
    return 0;
    }
    if(set2>=2){
     cout<<" ";
     continue;
    }
}

system("cls");
}
for(int m=0;m<size;m++){
   for(int n=0;n<size;n++){
    if(m==urow&&n==ucol&&o=='l'&&array[m][n]!=9&&array3[m][n]==0&&array2[m][n]!='f')
     {
     temp=array[m][n];
    
     if(temp==0){
     array2[m][n]=48;
     array3[m][n]=1;
     }
    
     if(temp==1){
     array2[m][n]=49;
     array3[m][n]=1;
     }
    
     if(temp==2){
     array2[m][n]=50;
     array3[m][n]=1;
     }
    
     if(temp==3){
     array2[m][n]=51;
     array3[m][n]=1;
     }
    
     if(temp==4){
     array2[m][n]=52;
     array3[m][n]=1;
     }
    
     if(temp==5){
     array2[m][n]=53;
     array3[m][n]=1;
     }
    
     if(temp==6){
     array2[m][n]=54;
     array3[m][n]=1;
     }
    
     if(temp==7){
     array2[m][n]=55;
     array3[m][n]=1;
     }
    
     if(temp==8){
     array2[m][n]=56;
     array3[m][n]=1;
    
     }
    total=total+array[m][n];
    }
    if(m==urow&&n==ucol&&o=='r'&&array3[m][n]==0&&array4[m][n]==0&&counterf<10)
    {
     array2[m][n]='f';
     array4[m][n]=1;
     counterf=counterf+1;
   
    }
    else if(m==urow&&n==ucol&&o=='r'&&array4[m][n]==1)
    {
     array2[m][n]=178;
     array4[m][n]=0;
     counterf=counterf-1;
   
    }
  
   cout<<array2[m][n]<<" "<<" ";
   
}
cout<<endl<<endl;
}
if(array[urow][ucol]==9&&o=='l'&&array2[urow][ucol]!='f'){
   system("cls");
   for(m=0;m<8;m++){
    for(int n=0;n<8;n++){
     if(array[m][n]==9)
     {
      array2[m][n]='X'; // x is mine
     }
    
      cout<<array2[m][n]<<" "<<" ";
    
    
    }
     cout<<endl<<endl;
    }

   cout<<"you Just hit a mine.ohhh thats sad.better luck next time : "<<endl;

   break;
}
if(total==totalf){
   int temp4=time/1000;
   system("cls");
   for(int r=0;r<8;r++){
    for(int l=0;l<8;l++){
     if(array2[r][l]=='f'|| array[r][l]==9){
      array2[r][l]='X';
     }
     cout<<array2[r][l]<<" "<<" ";
    }
    cout<<endl<<endl;
   }
   cout<<"congratulation You win :"<<endl;
   highscore(temp4);
   break;
}
  
}
}
void highscore(int & b){
char array[20];
ifstream ifile;
ifile.open("highscore.txt");
ofstream ofile;
ofile.open("highscore.txt");
int a;
while(!ifile.eof()){
ifile>>a;
if(a>b){
   ofile<<a; ofile<<" ";
   cout<<"Enter name ";
   cin.getline(array,20,'\n');
   for(int i=0;array[i]!='\0';i++){
    ofile<<array[i];
   }
}
}
ifile.close();
ofile.close();
}
int main (){
int array[8][8]={0};
int array3[8][8]={0};
int array4[8][8]={0};
char array2[8][8];
int size=8;
int choice;
int choice2;
cout<<"Enter 1 for Help and anyother key to play game "<<endl;
cin>>choice;
if(choice==1){
help();
cout<<endl<<endl;
cout<<"To play game now.Press 3 ";
cin>>choice2;
}
if(choice>=2||choice2==3){

srand(time(0));

mines(array,size);
numbers(array,size);

/*for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
cout<<" "<<array[i][j]<<" ";
}
cout<<endl<<endl;
}
*/
board(array2,size);
axis(array,array2,array3,array4,size);
char o;
cout<<"Do you want to countinue or exit.Enter R for replay or E for exit ";
cin>>o;
switch(o){
case 'r':
case 'R':
{
system("cls");
for(int f=0;f<8;f++){
   for(int n=0;n<8;n++){
    array[f][n]=0;
   array3[f][n]=0;//this array checks whether mine is reveal or unreveal
   array4[f][n]=0; // this array checks that whether blocks has some flag or not
   array2[f][n]=178;
   }
}
mines(array,size);
numbers(array,size);
//board(array,size);
axis(array,array2,array3,array4,size);
break;
}
case 'e':
case 'E':
cout<<"Thanks for Playing.Allah Hafiz"<<endl;
system("PAUSE");
break;

default:
cout<<"Invalid option Entered"<<endl;
break;
}
}
return 0;
}

code 2 you can try this code also

#include <iostream>

#include <vector>

#include <queue>

#include <utility>

#include <random>

#include <ctime>

using namespace std;

//matrix is a 2d vector of chars, used for both our map and our mask

typedef vector<vector<char> > matrix;

//below are our minesweeper map params

const int x_dim = 10, y_dim = 10, numMines = 10;

/********************************************

Add a mine to our map

returns true if mine added

false if mine wasn't added (attempted to add a mine to a location that already had one)

also updates proximity values in the map as well

*********************************************/

bool addMine(matrix& map)

{

     //Generate a random location for this mine

     int x = rand() % x_dim, y = rand() % y_dim;

     //Add the mine, if one isn't already there

     if(map[x][y] != '*')

     {

            map[x][y] = '*';

            //walk through all neighboring locations and increment their proximity counts

            for(int dx = x-1; dx <= x+1; dx++)

                    for(int dy = y-1; dy <= y+1; dy++)

                            if(dx >= 0 && dx < x_dim && dy >= 0 && dy < y_dim)

                                   if(map[dx][dy] != '*') //Don't update proximity count for mine locations

                                           if(map[dx][dy] == '.')

                                                  map[dx][dy] = '1'; //initial proximity, set to 1

                                           else

                                                  map[dx][dy]++; //otherwise, increment current count (works even with chars so long as count never exceeds 9)

            return true;

     }

     //random location already contains a mine

     return false;

}

/*****************************************************************

reveals the specified location of the map/mask

expands areas that are not in proximity to a mine as well

returns true if a mine was revealed (ie game over)

******************************************************************/

bool revealLocation(matrix& map, matrix& mask, int x, int y)

{

     //reveal the location

     mask[x][y] = '.';

     //if location is a mine, game over, just return true

     if(map[x][y] == '*')

            return true;

     //If our location isn't in proximity to a mine

     //we reveal all neighboring locations

     //dots indicate no neighboring mine

     if(map[x][y] == '.')

{

            //openLocations holds neighboring locations that also

            //are not in proximity to a mine

            queue<pair<int, int> > openLocations;

            openLocations.push(make_pair(x, y));

            //Walk through all dot locations and reveal their neighboars

            while(!openLocations.empty())

            {

                    //Get the next location from our queue

                    pair<int, int> next = openLocations.front();

                   

                    //The two for loops iterate over a 3x3 block within our map

                    //surrounding the point next. It will check the point itself

                    //as well, which is redundant, but we hardly need highly

                    //optimized code here

                    for(int dx = next.first-1; dx <= next.first+1; dx++)

                    {

                            for(int dy = next.second-1; dy <= next.second+1; dy++)

                            {

                                   //Let's make sure the current location is within the

                                   //bounds of our map. If next is an edge location, then

                                   //we'll be iterating over some points outside the map

                                   //So just ignore those points

                                   if(dx >= 0 && dx < x_dim && dy >= 0 && dy < y_dim)

                                   {

                                           //if this neighbor is a dot location and hasn't

                                           //previously been revealed, add it to our list

                                           if(map[dx][dy] == '.' && mask[dx][dy] == '#')

                                                  openLocations.push(make_pair(dx, dy));

                                           //reveal this neighboring location

                                           mask[dx][dy] = '.';

                                   }

                            }

                    }

                    //We're done with the current location in our queue, so we can remove it

                    openLocations.pop();

            }

     }

     return false;

}

/******************************************************

returns a count of the remaining masked locations

used to determine if only mines are masked (ie our win condition)

*******************************************************/

int countMask(matrix& mask)

{

     int count = 0;

     for(int x = 0; x < x_dim; x++)

            for(int y = 0; y < y_dim; y++)

                    if(mask[x][y] == '#') count++;

     return count;

}

int main()

{

     srand((unsigned int)time(NULL));

     //map contains our mines and proximity values

     //Only unmasked locations of map will be visible though

     //as tracked by our following mask matrix

     matrix map;

     //mask tracks revealed locations

     //# char indicates unrevealed locations

     //. char indicated revealed locations

     matrix mask;

     //Generate our map and mask

     for(int i = 0; i < x_dim; i++)

     {

            map.push_back(vector<char>(y_dim, '.'));

            mask.push_back(vector<char>(y_dim, '#'));

     }

     int mineCount = 0;

  

     //loop to add mines until we have a full minefield

     do

     {

            if(addMine(map))

                    mineCount++;

     }while(mineCount != numMines);

     int x_in, y_in;

     do

     {

            //Display the masked minefield

            //output column indices first

            cout << " 0123456789" << endl;

            cout << " ----------" << endl;

            //loop through our rows

            for(int x = 0; x < x_dim; x++)

            {

                   //output each row index before the row itself

                   cout << x << "|";

                   //loop through all the columns for this row

                   for(int y = 0; y < y_dim; y++)

                   {

                           //if location is still masked, display mask char

                           //otherwise display the underlying map value

                           if(mask[x][y] == '#')

                                   cout << '#';

                           else

                                   cout << map[x][y];

                   }

                   cout << endl;

            }

            //Wait for user input to reveal a location

            cin >> x_in >> y_in;

            //pass the specified location to our revealLocation function

            //revealLocation returns true if a mine was unmasked

            if(revealLocation(map, mask, x_in, y_in))

            {

                   cout << "You set off a mine. Game over!" << endl;

                   break;

            }

            //Count our masked location, if == numMines, then only mines are left

            //and player has won the game

            if(countMask(mask) == numMines)

            {

                   cout << "You have found all the mines. Congratulations!" << endl;

                   break;

            }

    }while(1);

    map.clear();

    mask.clear();

    cout << endl;

    system("pause");

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
ELEN 1301-01 Programming Assignment #11 Due date: November 11, 2015. Wednesday (At the beginning of class.)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ELEN 1301 Programming Assignment #5. Purpose of the program : Calculating class grade percentage. Section 1...

    ELEN 1301 Programming Assignment #5. Purpose of the program : Calculating class grade percentage. Section 1 : Enter the number of classes you attended (0 ~ 12) 5%. Section 2 : Enter the discussion board score you earned (0 ~ 120) 5%. Section 3 : Enter the quiz score you earned (0 ~ 240) 10%. Section 4 : Enter the programming assignment score you earned (0 ~ 120) 20%. Section 5 : Enter the midterm exam score you earned (0...

  • Please use C++ and output have to look like that Create a menu driven C++ program...

    Please use C++ and output have to look like that Create a menu driven C++ program with functions. There must be four functions, calculating the size of area of circle, rectangle, triangle, and parallelogram. You are required to create those four functions and invoke them from the main program in order to reccive any credit. Please Submit: . A flowchart of your program with equations and expected results. 4 points) 2. Printout of your C++program with a heading comment, also...

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • R Assignment 1 Due Date: The assignment will be accepted for marking at the beginning of...

    R Assignment 1 Due Date: The assignment will be accepted for marking at the beginning of class, January 29th, 2019. Assignments which are submitted after this deadline will not be accepted for marking Your assignment must be submitted as a paper copy of a typed document created using a word-processing program such as Word or Open Office. At the top of the first page of your assignment, type the following information in the upper le ft-hand corner Last Name, First...

  • Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing...

    Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

  • Programming Assignment 3 CSCI 251, Fall 2015 Infinite Series Trigonometric and math functions are...

    Programming Assignment 3 CSCI 251, Fall 2015 Infinite Series Trigonometric and math functions are usually calculated on computers using truncated Taylor series (an infinite series). An infinite series is an infinite set of terms whose sum is a particular function or expression. For example, the infinite series used to evaluate the natural log of a number is (x - 1)2 (x-1)3 (x-1)* (x-1)5 2 4 where x E (0, 2], or 0

  • COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning...

    COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning Outcome #2: Create and utilize arrays to store lists of related data Programming Problem You have been hired to create a C++ program to simulate the lottery. Your program allows users to see how often their lottery number choices match a randomly generated set of numbers used to pick lottery winners. The company, "How Lucky Are You?, Inc." wants a modular, professional and user-friendly...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit...

    Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit 1 zip file containing 4 files below to iLearn by the deadline. [30 points] ● 3 JAVA Files: TableBmiPro.java, MyOwnIdea.java. DiceRoll.java [24 points] ● 1 File: Make a document that shows the screen captures of execution of your programs and learning points in Word or PDF. Please make sure you capture at least 2 executions for 1 program, so 6 screen captures and one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT