tutorial04(1).pptx - CSCI1120 Introduction to Compu ting...

Info icon This preview shows pages 1–15. Sign up to view the full content.

CSCI1120 Introduction to Compu ting Using C++ Tutorial 10: assignment 2 && built-in functions Li Le SHB 1013 lil @cse.cuhk.edu.hk 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Assignment 2 Part 1: Basic Requirement Part 2: Problem Introduction Part 3: Analysis of the problem Part 4: Structure of main function Part 5: Sub-functions Part 6: Tips for program 2
Image of page 2
1 Basic Requirement Due: 20:00, Wed 12 Oct 2016 Submit your program named dotsboxes.cpp to CU eLe arning. Must contain the required functions. No global variable is allowed. Your program should be free of compilation errors an d warnings. Your program should include suitable comments. No plagiarism! 3
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Outline Part 1: Basic Requirement Part 2: Problem Introduction Part 3: Analysis of the problem Part 4: Structure of main function Part 5: Sub-functions Part 6: Tips for program 4
Image of page 4
2.1 Problem Description (a) Dots and Boxes : two-player paper-and-pencil game . Starting with an empty grid of dots, two players take turns a dding one horizontal or vertical line between two un-joined adjacent dots. A player who completes the fourth side of a 1×1 box earns one point (two points in one step is possible) and takes an e xtra turn . When grid is full, print out the results. 5
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

2.1 Problem Description (b) First 16 digits indicate if there is a line in the 16 positions (s hown in the figure); last 2 digits denote the scores. Score for player 1 Score for player 2 6
Image of page 6
2.2 Demo 7
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Outline Part 1: Basic Requirement Part 2: Problem Introduction Part 3: Analysis of the problem Part 4: Structure of main function Part 5: Sub-functions Part 6: Tips for program 8
Image of page 8
3.1 Grid Representation Here requires us to use a long long variable storing 1 8 digits. long long grid; First 16 digits to connect dots (e.g. plot vertical or ho rizontal lines), last 2 digits store players’ scores. Do not initialize a number with leading ‘0’ for this var iable. Otherwise, it’s treated as octal number. 016 -> 14 in decimal. 9
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

3.2 Program flow Empty Grid Player input Update grid Valid? Yes! No! Update score Display grid and scores Yes! Score? Change player No! Print game result End? Yes! No! 10
Image of page 10
Outline Part 1: Basic Requirement Part 2: Problem Introduction Part 3: Analysis of the problem Part 4: Structure of main function Part 5: Sub-functions Part 6: Tips for program 11
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

4.1 Pseudocode for main function 1 initialize and display the grid; 2 while (grid is not full) 3 Input the pos; 4 While (input is not valid) 5 warning and input again; 6 End 7 Update grid; 8 Display grid; 9 If (current player scores) 10 Keep current player; 11 else 12 Change to another player; 13 end 14 end 15 print out the results; 12
Image of page 12
Outline Part 1: Basic Requirement Part 2: Problem Introduction Part 3: Analysis of the problem Part 4: Structure of main function Part 5: Sub-functions Part 6: Tips for program 13
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Required sub-functions: displayGrid : display chart of the grid board; isFilled: to see if a position is empty or not; playerScore: return one player’s score; updateGrid
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '15

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern