+ All Categories
Home > Documents > C++ Lecture -

C++ Lecture -

Date post: 09-Jan-2016
Category:
Upload: enoch-park
View: 227 times
Download: 3 times
Share this document with a friend

of 12

Transcript
  • CIS 214 C++ Programming

    Wednesday, July 16, 2014

    CIS 214 C++ Programming - Summer 2014 1

  • PDF: h7p://www.cplusplus.com/les/tutorial.pdf Online: h7p://www.cplusplus.com/doc/tutorial/ Syllabus: h7ps://canvas.pasadena.edu/courses/880280/assignments/syllabus C++ How to Program, 9th ed (or earlier) Deitel & Deitel, PrenIce Hall, 2013 C++ Primer, 5th ed S. Lippman, J. Lajoie, and B. Moo, Addison-Wesley, 2012

    REFERENCES

    CIS 214 C++ Programming - Summer 2014 2

  • ASCII h7p://www.cplusplus.com/doc/ascii/ BOOLEAN h7p://www.cplusplus.com/doc/boolean/ RAND(): h7p://www.cplusplus.com/reference/cstdlib/rand/ ONLINE: h7p://www.cplusplus.com/doc/tutorial/ Program Structure

    Complete all chapters Compound Data Types

    Complete all chapters

    PDF: h7p://www.cplusplus.com/les/tutorial.pdf Page 1 85

    READING ASSIGNMENTS (Week of July 14, 2014)

    CIS 214 C++ Programming - Summer 2014 3

  • Implement a class called ArrayCreator that contains a private data structure consisIng a 2D integer array. This array holds 20 integer elements, with each element poin8ng to another array of 4 integer elements as follows: Write a create2DArray() funcIon in this class to dynamically allocate the

    above data structure Write a delete2DArray() funcIon in this class to dynamically de-allocate

    the above data structure

    LAB ASSIGNMENT: REVIEW

    CIS 214 C++ Programming - Summer 2014 4

    Primary array of 20 integer elements, namely arr[20]

    1 2 3 20

  • Dynamically allocate a 2D array of 20x4:

    int** arr = new int*[20];!for(int i = 0; i < 20; ++i)! arr[i] = new int[4];!

    !! Dynamically free a 2D array (remember the NULL assignment for safety)

    for(int i = 0; i < 20; ++i) {! delete [] arr[i];!!arr[i] = NULL;!

    }!delete [] arr;!arr = NULL;!!

    LAB ASSIGNMENT: REVIEW

    CIS 214 C++ Programming - Summer 2014 5

  • (50 Points Total) Implement a dynamic Login System for our CIS14 Computer Labs. Assuming there are 4 computer labs (Lab#1-#4) in our IT Building on campus, each lab having 10 computers (Computer #1-10): Lab#1: 10 computers Lab#2: 10 computers Lab#3: 10 computers Lab#4: 10 computers The user can log into any available computers with any ID that is 5 ASCII characters long (e.g., Ab231, !pas!, ab00~, etc). Logout is only possible with the exact spelling of the ID in the system. To begin the user is presented with the following SELECTION MENU with the 4 opIons:

    ! !!

    HOME PROJECT #8: 7/16/14

    CIS 214 C++ Programming - Summer 2014 6

  • In this assignment, you are asked to implement a LoginSystem class as follows: class LoginSystem {!!

    ! !// 2D array holding Lab#s and corresponding Computer#s!! !string** labs;!

    !!public:!

    !LoginSystem();!!~LoginSystem();!

    !!void showStatus();!!void showMenu();!

    !!void login();!!void logout();!!void search();!

    !};!!

    HOME PROJECT #8 CONTINUED: 7/16/14

    CIS 214 C++ Programming - Summer 2014 7

  • Grading for this assignment is broken down into how you implement each of the following elements of your Login System and the correctness of your end result for each element. Please pay a7enIon to your Syntax/Eciency/Logic for each element. (10 Points) int main() InstanIate your LoginSystem Invoke showStatus() and showMenu() Enable selecIon of the 4 menu choices

    (5 Points) LoginSystem() Dynamic memory allocaIon of your 2D array, labs (5 Points) ~LoginSystem() Dynamic memory de-allocaIon of your 2D array, labs

    HOME PROJECT #8 GRADING BREAKDOWN

    CIS 214 C++ Programming - Summer 2014 8

  • (10 Points) void showStatus() This funcIon prints the status of all Lab#/Computer# slots as follows When a Lab#/Computer# slot is available, not in use, the program displays the string empty

    for that slot When a Lab#/Computer# slot is taken the program prints the user ID occupying that slot IniIally when no one is logged in, so all Lab#/Computer# slots should be empty: (5 Points) void showMenu() This funcIon prints all available user opIons, namely, LOGIN, LOGOUT, SEARCH, and QUIT as

    follows:

    ! ! ! ! !!

    HOME PROJECT #8 - CONTINUED: 7/16/14

    CIS 214 C++ Programming - Summer 2014 9

  • (5 points) When LOGIN is selected: The program prompts Enter your 5-character ID to login: The program checks whether the ID contains any 5 ASCII characters If not the program repeats the prompt unIl it receives an ID containing 5 ASCII characters Ajer a valid ID is received the program prompts Enter the Lab #: The program checks whether the Lab # is a number between 1-4 If not the program repeats the prompt unIl it receives a valid Lab # Ajer a valid Lab # is received, the program prompts Enter the Computer #: The program checks whether the Computer # is a number between 1-10 If not the program repeats the same prompt unIl it receives a valid Computer # At the end of the LOGIN process the program invokes showStatus() and showMenu()

    HOME PROJECT #8 - CONTINUED: 7/16/14

    CIS 214 C++ Programming - Summer 2014 10

  • (5 points) When LOGOUT is selected: The program prompts "Enter your 5-character ID to logout: The program checks whether the ID contains any 5 ASCII characters If not the program repeats the prompt unIl it receives a valid ID If a valid ID is received but not found in your 2D array data structure, the program prompts

    That user is not logged in. If a valid ID is found in your 2D array data structure the program prints User [ID] is logged

    out At the end of the LOGOUT process the program invokes showStatus() and showMenu()

    HOME PROJECT #8 - CONTINUED: 7/16/14

    CIS 214 C++ Programming - Summer 2014 11

  • (5 points) When SEARCH is selected: The program prompts Enter a 5-character ID to search: The program checks whether the ID contains any 5 ASCII characters If not the program repeats the prompt unIl it receives a valid ID If a valid ID is received but not found in your 2D array data structure, the program prompts

    That user is not logged in. If the ID is found in your 2D array data structure the program prints User [ID] is in Lab

    #[NUM], Computer #[NUM] At the end of the LOGOUT process the program invokes showStatus() and showMenu() (5 points) When QUIT is selected: The program exits, de-allocaIng all of the dynamic memory in use

    HOME PROJECT #8 - CONTINUED: 7/16/14

    CIS 214 C++ Programming - Summer 2014 12


Recommended