COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
$149.99$275.00
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 7 Lab Polymorphism
This lab introduces students to the concepts of polymorphism, early binding, late binding, abstract classes, and virtual class functions. This will be done in the context of performing calculations on basic geometrical shapes. Polymorphism is a very powerful extension of inheritance, and by using pointers to the base class, it allows access to derived class objects and their functions based on the context that they are called in.
Description
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 7 Lab Polymorphism
This lab introduces students to the concepts of polymorphism, early binding, late binding, abstract classes, and virtual class functions. This will be done in the context of performing calculations on basic geometrical shapes. Polymorphism is a very powerful extension of inheritance, and by using pointers to the base class, it allows access to derived class objects and their functions based on the context that they are called in.
The lab will require the creation of a base geometric class, called Shape, and two sub classes, Circle and Rectangle, that are derived public from the class Shape. From there, objects of both the Circle and the Rectangle classes will be created, as will an array of pointers to the base class Shape. By using the instantiated objects and the object pointers, both static and dynamic binding will be demonstrated.
Deliverables
- Submit a single NotePad file containing the source code for all the lab files to the Week 7 Dropbox. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_Lab5.txt.
Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes. - Submit a lab report (a Word document) containing the following information to the Week 7 Dropbox.
- Include your name and the lab or lab exercise number.
- Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.
- Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
- Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
- A UML Diagram: This should show all the classes, class members, access specifiers, data types, and function arguments, along with all of the class-to-class relationships.
- Answers to Lab Questions: Include the answers to all the lab questions that are asked in the lab steps.
Each lab exercise should have a separate section in the lab-report document.
Your lab grade is based upon
- the formatting of your source code;
- the use of meaningful identifiers;
- the extent of the internal documentation;
- the degree to which an exercises’ specifications are met; and
- the completeness of your lab report.
iLAB STEPS
STEP 1: Create a New Multifile Project
Create a new multifile project with three classes: the base class Shape, the class Circle (derived public from Shape), and the class Rectangle (derived public from Shape). The classes will have the following requirements.
- The class Shape should be an abstract class with the following pure virtual functions.
- area()
- perimeter()
- The class Circle should be derived public from the class Shape and override both the area() and the perimeter() functions.
- The perimeter() function should correctly calculate the circumference of a circle, given a radius.
- The area() function should correctly calculate the area of a circle, given a radius
- Include all the necessary accessor and mutator functions to accomplish the requirements of the class.
- The class Rectangle should be derived public from the class Shape and override both the area() and the perimeter() functions.
- The perimeter() function should correctly calculate the circumference of a rectangle, given its dimensions.
- The area() function should correctly calculate the area of a rectangle, given its dimensions.
- Include all the necessary accessor and mutator functions to accomplish the requirements of the class.
STEP 2: Create the Test Function
Instantiate at least one object of each of the Circle and the Rectangle classes. Provide appropriate constructors for both that will accept the necessary initialization arguments to provide the information required for all the class member functions. Exercise and test each member function of both classes for correct calculations and output.
STEP 3: Add a Base Class Pointer Array and an Additional Function
Add to the test function a base class array of pointers of the same dimension as the total number of Circle and Rectangle objects that were created in the previous step. Use this pointer array to access the Circle and the Rectangle objects to call a new, nonclass member function that will display all the information about each object.
- Circle objects should display radius, circumference, and area.
- Rectangle objects should display dimensions, perimeter. and area.
The information-display function should accept as its calling parameter a pointer of the class Shape.
Run the test function to demonstrate static (early) binding using the derived class objects calling their member functions, and run the test function to demonstrate dynamic (late) binding using the assigned Shape class pointers to call the nonclass, member-display-information function.
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 6 Lab Overloaded Operators
This lab is to introduce students to the concept of operator overloading as member functions of a class. This will be done in the context of creating a class that will perform four basic mathematical operations on complex numbers.
The C++ compiler has defined operators for all the arithmetic and assignment operations for its native data types, such as integer, float, double, and so forth. However, for user-defined data types, such as classes and structures, these operations are undefined.
C++ allows the programmer to create new definitions for these operators so that they can operate specifically on these user-defined data types. Which set of operators is actually called and implemented is decided during the compilation, and it is based on the data types of the operands involved in the operation.
The ability to define a new set of data-type, dependent operations on existing operators, or functions, is called operator overloading.
Deliverables
- Submit a single Notepad file containing the source code for all files of the lab to the Week 5 Dropbox. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_Lab5.txt.
Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes. - Submit a lab report (a Word document) containing the following information to the Week 6 Dropbox.
- Include your name and the lab or lab exercise number.
- Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.
- Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
- Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
- A UML diagram: This should show all the classes, class members, access specifiers, data types, and function arguments, along with any and all class-to-class relationships.
- Answers to Lab Questions: Include the answers to any and all lab questions asked in the lab steps.
Each lab exercise should have a separate section in the lab-report document.
Your lab grade is based upon
- the formatting of your source code;
- the use of meaningful identifiers;
- the extent of internal documentation;
- the degree to which an exercises’ specifications are met; and
- the completeness of your lab report.
iLAB STEPS
STEP 1: Create a New Multifile Project
Create a new multifile project, and create a class to model complex-number, mathematical operations using overloaded operators and add main() test functions to test the operations.
- Create a class for complex numbers that will provide the means to store both the real and the imaginary values of a complex number.
- Design and add overloaded operators to perform correct and complex mathematical operations on objects of the complex-number class.
STEP 2: Create and Add the Overloaded Operators
- Overload the addition operator (+) to perform complex mathmatical addition on two objects of the complex-number class.
- Overload the subtraction operator (-) to perform complex mathmatical subtraction on two objects of the complex-number class.
- Overload the multiplication operator (*) to perform complex mathmatical multiplication on two objects of the complex-number class.
- Overload the division operator (/) to perform complex mathmatical division on two objects of the complex-number class.
- Overload the assignment operator (=) to assign all the data values of an object in the complex-number class to another object in the complex-number class.
STEP 3: Test the Overloaded Operators
Create at least three objects of the complex-number class in function main() and use them to perform the following operation tests.
- Demonstrate the correct operation of the complex addition overloaded operator.
- Demonstrate the correct operation of the complex subtraction overloaded operator.
- Demonstrate the correct operation of the complex division overloaded operator.
- Demonstrate the correct operation of the complex multiplication overloaded operator.
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 5 Lab Pointers and Pointer Operations
This lab will explore the use of pointers in several ways. Pointers will be used to dynamically allocate memory for new class objects on demand from the user, and they will be used to access class-member functions. Pointer arithmetic will be used to access and sort class objects according to criteria explained in the lab.
Pointers are, essentially, address variables, or variables that hold as their value the address of other variables. In terms of memory management, they are very powerful devices, and they more closely and efficiently use the actual internal hardware registers of the microprocessor that the program operates on.
Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.
The Resistor class created in the Week 2 lab will be used as the class that the pointer operations will be used upon. The lab also requires the use of accessor functions and static data members, which may need to be added to the Resistor class definition and implementation.
Deliverables
- Submit a single Notepad file containing the source code for all the files of the lab to the Dropbox for Week 5. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_Lab5.txt.
Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes. - Submit a lab report (a Word document) containing the following information to the Dropbox for Week 5.
- Include your name and the lab or lab-exercise number.
- Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.
- Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
- Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
- A UML diagram: This should show all classes, class members, access specifiers, data types, and function arguments, along with any and all class-to-class relationships.
- Answers to Lab Questions: Answer any and all lab questions included in the lab steps.
Each lab exercise should have a separate section in the lab-report document.
Your lab grade will be based upon
- the formatting of your source code;
- the use of meaningful identifiers;
- the extent of internal documentation;
- the degree to which an exercises’ specifications are met; and
- the completeness of your lab report.
iLAB STEPS
STEP 1: Create a Multifile Project
Create a new multifile project using the Resistor class developed in Week 1, and include a new main() test function.
STEP 2: Modify the Resistor-Class Definition
- Add a static data member of the class Resistor to keep track of the number of Resistor objects that are dynamically created. This will also be used to limit the number of objects that are dynamically created to the maximum array size of the pointer array in the test function main().
- In the Resistor constructor, use a random-number generator to randomly assign a nominal resistance value to the object between 1,000 and 10,000 ohms. The resistance values are not required to be standard resistance values.
STEP 3: Create the Test Function Main() and the Support Function
- Create an array of pointers of type Resistor.
- Use elements of the pointer array to allow the user to dynamically allocate memory and to instantiate objects of the Resistor class.
- Use the indirect member-selection operator (pointer) in the test routine to access function members of the Resistor class.
- Write a new, nonclass function called in function main() to sort the pointers to the Resistor objects in order from lowest nominal resistance value to highest, passing a pointer to the Resistor-object pointer as the only passed data argument.
- Display the sorted Resistor objects according to the nominal resistance value, from lowest to highest.
- Within the sorting function, use pointer arithmetic to access the individual Resistor objects.
- Function main() should also ensure that there are no memory leaks when the program ends.
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 4 Lab Composition
This lab requires you to use C++ class composition to implement a single pole-filter design program. The program will allow the user to specify resistor and capacitor values and filter type. Once all the user parameters are specified, the program will return the cutoff frequency values for the filter.
Composition may be thought of as a has-a relationship for objects, as compared to inheritance, which may be described as an is-a relationship for objects.
You are required to use two component classes: one for a resistor object and one for a capacitor object. You are then to define and implement a filter class that will contain one object of each the resistor and the capacitor classes in order to create the filter and its characteristics.
The Resistor class created in the Week 2 iLab may be used both as the class definition for the resistor object and as a template or a guide for the capacitor-class definition.
The lab also requires you to implement your program in a multiple-file project and create both cpp and h files for each class defined. In addition, the program will have the capacity to save all filter parameters to a text file and read previously designed filter parameters from a text file.
Deliverables
- Submit a single .zip file containing the source code for all the files of the lab to the Dropbox for Week 4. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_FirstName_Lab4.zip.
Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes. - Submit a lab report (a Word document) containing the following information to the Dropbox for Week 4.
- Include your name and the lab or lab-exercise number.
- Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.
- Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
- Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
- A UML diagram:
This should show all classes, class members, access specifiers, data types, and function arguments, along with the composition relationship of the classes.
- Answers to Lab Questions:
The answers to any and all lab questions are included in the lab steps.
Each lab exercise should have a separate section in the lab-report document.
Your lab grade will be based upon
- the formatting of your source code;
- the use of meaningful identifiers;
- the extent of internal documentation;
- the degree to which an exercises’ specifications are met; and
- the completeness of your lab report.
iLAB STEPS
STEP 1: Create a Multifile Project for the Composition Lab
- Add three classes to the project: a Filter class, a Capacitor class, and a Resistor class.
- You may use the Resistor class files from the Week 2 lab for this lab.
- The Capacitor class should be modeled after the Resistor class for class members and operation.
STEP 2: Filter-Class Definition
The Filter class should have, at a minimum, the following capabilities.
- a resistor-object data member
- a capacitor-object data member
- a cutoff frequency (in Hertz) of the RC filter
- maximum and minimum cutoff frequencies, based on the maximum and minimum in-tolerance values of the capacitor and the resistor object
- a filter type, either low pass or high pass
- allow the user to enter new values for the filter, including
6.1. resistor tolerance and nominal resistance;
6.2. capacitor tolerance and nominal capacitance; and
6.3. filter type - provides the ability to write all capacitor, resistor, and filter data members to a formatted text file and allows the user to name the file
- provides the ability to read all capacitor, resistor, and filter data members from a formatted text file and allows the user to enter the file name and correctly handles a file-not-found error
STEP 3: Test-Program Operation
- All data-input and data-display operations (cin and cout) should be done in the function main() test program.
- The test program should instantiate at least one object of the class Filter.
- The user should enter values for all the data members of the Filter, Resistor, and Capacitor classes.
- The Filter class should then calculate and display the correct maximum and minimum cutoff frequencies.
- The test program should then display all Filter, Resistor, and Capacitor data members.
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 3 Lab Inheritance
This lab introduces you to writing a C++ program to implement the concept of class inheritance using different types of bank accounts as a model. In this lab, you will create a base class, called CBankAccount, and two additional classes (each derived from CBankAccount), called CSavingsAccount and CCheckingAccount. You will then test the operations of each class in function main() to simulate the transactions of both a checking account and a savings account.
Deliverables
- Submit a single Notepad file containing the source code for all the files of the lab to the Dropbox for Week 3. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example, YourLastName_Lab3.txt.
Each program should include a comment section that includes (minimally) your name, the lab and exercise number, and a description of what the program accomplishes. - Submit a lab report (a Word document) containing the following information to the Dropbox for Week 3.
- Include your name and the lab or lab-exercise number.
- Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.
- Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
- Summary and Conclusions: Include a summary of what the lab demonstrated and any conclusions drawn from the testing of the lab program.
- Provide a UML diagram showing the base and the derived class relationships, access specifiers, data types, and function arguments.
- Answers to Lab Questions: Answer any and all of the lab questions included in the lab steps.
Summary: Write a statement summarizing your predicted and actual output. Identify and explain any differences.
Conclusions: Write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
Each lab exercise should have a separate section in the lab-report document.
Your lab grade is based upon
- the formatting of your source code;
- the use of meaningful identifiers;
- the extent of internal documentation;
- the degree to which an exercises’ specifications are met; and
- the completeness of your lab report.
iLAB STEPS
STEP 1: Create the Multifile Project and the Main (Base) Class
Create a new project that consists of the base class BankAccount.
The BankAccount class should contain, at minimum, the following members.
- It should contain data members to store a bank customer’s balance and account number. These should be of different and appropriate data types.
- It should have function members that do the following:
- set the account number;
- return the account number;
- return the account balance;
- deposit money into the account; and
- withdraw money from the account.
STEP 2: Create the CheckingAccount Class Derived From the BankAccount Class
The class CheckingAccount should contain, at a minimum, the following members.
- It should contain a data member to keep track of the number of withdrawal transactions made on the account. Whenever a withdrawal is made, this number should be incremented.
- Override the base class, withdraw-money function, and add the capability to deduct transaction fees from an account using the following guidelines.
- The checking account is allowed three free transactions. For each successful withdrawal transaction past the three free transactions, there will be a service fee of 50 cents per transaction. The service fee should be deducted from the account balance at the time the transaction is made.
- If there are insufficient funds in the account balance to cover the withdrawal plus the service fee, the withdrawal should be denied.
- The function should return a value to indicate whether the transaction succeeded or failed. Transaction fees should be deducted only from successful transactions, but the transaction count should be incremented in either case.
STEP 3: Create the SavingsingAccount Class Derived From the BankAccount Class
The class CheckingAccount should contain, at a minimum, the following members.
- It should contain a data member to hold the daily interest rate. The daily interest rate can be calculated from a yearly interest rate by dividing the annual rate by 365.
- It should contain a data member to keep track of the number of days since the last transaction or balance inquiry. This should be updated using a random-number generator (reference Lab 1) that will return a value representing the number of days between 0 and 7, inclusive. We will assume that this bank is open every day of the year.
- It should contain a data member to hold the interest earned since the last transaction or balance inquiry.
- It should contain a function member to set the annual interest rate.
- Utilize the base-class functions for both withdrawal and deposit operations for the savings account.
- Override the base-class-balance inquiry function to add calculating and adding interest to the account based on the daily interest rate, the current balance of the account, and the number of days since the last balance inquiry. This should be called only when a balance inquiry is made, not when a deposit or withdrawal transaction or an account number inquiry is made.
- If there are insufficient funds in the account balance to cover a withdrawal, the withdrawal should be denied. The number of days since the last transaction or balance inquiry and the interest calculations should still be made.
- A value should be returned to indicate whether a withdrawal transaction succeeded or failed.
- It should contain a function member to return the interest earned since the last transaction or balance inquiry.
- It should contain a function member to return the number of days since the last transaction or balance inquiry.
STEP 4: Test Program Operation
- All data-input and data-display operations (cin and cout) should be done in the function main() test program.
- The test program should create one checking account and one savings account with initial balances of $100 each using the functions defined in the class definitions. The test program should also assign a unique, five-digit account number to each account and assign an annual interest rate of 3% for the savings account.
- The test program should then display a menu that allows the user to select which option is to be performed on which account, including the following.
- Make a deposit and specify the amount to a selected or an entered account.
- Make a withdrawal and specify the amount to a selected or an entered account.
- Return the balance of a selected or an entered account.
- For deposit transactions, withdrawal transactions, and balance inquiries, the updated balance and any fees charged or interest earned should also be displayed.
- For the savings account, the number of days since last transaction should be displayed.
- Exit the program.
- Each account operation should display the account number and the account type.
Lab Questions
Please answer all the lab questions in the text file that is to be turned into the Dropbox. You are not required to copy the question text into your document, but all answers should be listed with the question number they answer.
- Were any base-class functions called or overloaded in either of the derived classes? If so, list which class and which function, and explain why they were either called or overloaded.
- Were any derived-class functions not explicitly called by the test program? If so, list which class and function, and explain why this was done.
- Which access attribute was used for each of the classes derived from the base class? Why was this access attribute chosen?
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 2 Lab Classes Objects and Encapsulation
This lab requires you to create a multifile C++ project in order to design and implement an object-oriented program using a class to model the characteristics and function of a resistor.
Deliverables
Submit a single Notepad file containing the source code for Exercise 1 to the Dropbox for Week 2. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name; see the following example: YourLastName_Lab1.txt.
Each program should include a comment section that includes (at a minimum) your name, the lab and exercise number, and a description of what the program accomplishes.
Submit a lab report (a Word document) containing the following information to the Dropbox for Week 2.
Include your name and the exercise number.
iLAB STEPS
STEP 1: Create a Multifile Project
Objective: Create a C++ console application that will model the characteristics of a resistor.
- Create a multifile project. Create and add to the project an h file containing the resistor-class definition.
- Create and add to the project a cpp file containing the implementation of the class-member functions.
- Create and add to the project a ccp file containing the main() function, which will instantiate a resistor object and test its member functions.
STEP 2: Required Class Members
The resistor class will, at minimum, have members that do the following.
- store the nominal resistance value of a resistor
- store the tolerance of a resistor
- initialize any and all nominal-resistance values to correct, EIA, nonzero values that are greater than 0 and less than 1,000,000 ohms
- initialize any and all resistance-tolerance values to correct, E12, E24, E48, or E96 resistance-tolerance values
- allow the nominal-resistance and tolerance values of a resistor object to be changed by the user
- All member functions should have a test message stating the name of the function. All the test messages should be displayed or not displayed, depending on the value of a Boolean variable declared in main().
- If the Boolean value = true, display the message.
- If the Boolean value = false, do not display the message.
STEP 3: Program Operations
- Function main() should instatiate two objects of class resistor.
- Function main() should display the current values of all resistor objects.
Function main() should also calculate and display the minimum and maximum in-tolerance resistance values of each resistor object from the resistor data members. - Function main() should allow the user to change the values of the nominal resistance and the resistor tolerance of both resistor objects, and it should also correctly handle out of numeric-range input. Main() is also responsible for making sure that the user can successfully enter only correct, EIA resistance and tolerance values.
The user should be given the following data-entry choices:
accept current EIA values for resistance and tolerance; - The function main() should display the new, modified values of the resistor object, including the new min and max in-tolerance resistance values.
- The function main() should be executed twice: once with the test messages displayed and once without.
STEP 4: Lab Questions
You are not required to copy the question text into your document, but all answers should be listed with the question number they answer.
- List the complete reference-source information for where you found the EIA standard resistor value and tolerance information.
- How was this reference discovered and where?
- The constructor requires the initialization values for the nominal resistance and the tolerance when an object is instantiated to be a correct E-series resistance and tolerance combination. Describe how this was accomplished in your program design and implementation.
- In the lab, you were required to provide mutator functions to change the nominal-resistance and tolerance values of a resistor object.
Describe how this was accomplished so that the user could not enter an invalid nominal-resistance and E-series tolerance combination. - Describe how this process was different and/or similar to how you implemented this validation in the class constructor.
COMP 220 COMP220 COMP/220 ENTIRE COURSE HELP – SOUTHERN ALBERTA INSTITUTE OF TECHNOLOGY (SAIT)
COMP 220 Week 1 Lab Two-Dimensional Arrays
This lab requires you to design and implement a C++ program to simulate a game of Blackjack between two to four players. Your program must incorporate a two-dimensional array to represent the suit and the value of each card dealt to a player, keep track of which cards have been dealt to which player, and use a random-number generator to pick each card to be dealt to a player.
Deliverables
- Submit a single Notepad file containing the source code for Lab 1 to the Dropbox for Week 1. Your source code should use proper indentation and be error free. Be sure that your last name and the lab number are part of the file name: for example,
Y ourLastName_Lab1.txt.
Each program should include a comment section that includes, at a minimum, your name, the lab and exercise number, and a description of what the program accomplishes. - Submit a lab report (a Word document) containing the following information to the Dropbox for Week 1.
- Include your name and the exercise number.
- Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.
- Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.
- Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For your conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
- Answers to Lab Questions: Answer any and all of the lab questions included in the lab steps.
Each lab exercise should have a separate section in the lab-report document.
iLAB STEPS
STEP 1: Starting Visual Studio
Create a new Visual Studio empty project, and add one C++ source code file.
STEP 2: Coding
Enter the following source, which will set up the 2D array and the recommended variable declarations. It is up to the student to design and implement the remainder of the program code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // Programmer: (put your name here) // Course: COMP220 // Assignment: Two-Dimensional Arrays // Description: The program will use a 2D array and a random-number // generation to play Blackjack and keep track of a playing-card deck. // Input: User data entry and a playing-card deck represented as a two- // dimensional array // Output: A screen display showing the current card hands of each player // and the dealer, their score, win and lose status, and a final representation // of the card deck after the game is over # include <iostream> # include <iomanip> # include <windows.h> using namespace std; void main (void) { bool bPlayerDraw[5]; //Boolean to determine if player holds (F) //or draws card (T) char cPlay = 'N' ; //Character variable for play game input char cCardDeck[4][13]; //Character array representing the card deck int iCard; //0 = 2 card //1 = 3 card //2 = 4 card //3 = 5 card //4 = 6 card //5 = 7 card //6 = 8 card //7 = 9 card //8 = 10 card //9 = jack card //10 = queen card //11 = king card //12 = ace card int iNumberOfDraws = 0; //Number of rounds of card draws int iSuit; //Suit array index //0 = diamonds //1 = hearts //2 = clubs //3 = spades // ASCII character display reference for display card suit symbols //3 = heart symbol //4 = diamond symbol //5 = club symbol //6 = spade symbol int iNumberOfPlayers = 0; //Number of players in current game int iPlayerCount[5]; //Integer array to holder each player's count //iPlayer[0] is always the dealer int iHighestCount = 0; //Highest count for a single game int k, m; //integer loop counters srand(GetTickCount()); //Seed the random-number generator //Main game loop //Enter your code here... |
A sample output of the program is below:
Welcome to Honest Sam’s Blackjack Table Glad to have you back!
Enter the number of players in the game.
There must be at least one player but no more than four.
Number of players: 3
[table]
, Card 1 , Card 2 , Card 3 , Total , Stats
Dealer , J♦ , 10♦ , 9♣ , 29 , Lose
Player 1, K♣ , 2♠ , 5♥ , 17 , Lose
Player 2 , J♣ , Q♥ , 10♥ , 30 , Lose
Player 3 , 3♦ , 8♣ , K♦ , 21 , Win!
[/table]
STEP 3: Program Specifications
- There is always a dealer in the game. The dealer draws 3 cards.
- There must be at least one other player (you) and up to a maximum of four other players (all played by you).
- Each player will draw 3 cards.
- All the cards for each player, including the first card dealt, are displayed, along with the suit symbol: spades ♠, clubs ♣, hearts ♥, or diamonds ♦.
- Each game will start with a new, 52-card deck, which is modeled on a real deck of cards.
- The card deck has 52 cards with no jokers.
- The card deck is represented by a two-dimensional array of data-type character, where the first dimension represents the suit and the second dimension represents the card in the suit, such as the following.
char CardDeck[4][13]; - At the start of each game, each element of the two-dimensional array is initialized to a value of ” “, or the “space” character.
- The deck has four suits, represented by the following dimension indices.
- 0 = diamonds
- 1 = hearts
- 2 = clubs
- 3 = spades
- Each suit has 13 cards: 2, 3, 4, 5, 6, 7, 8, 9 ,10, jack, queen, king, and ace.
- Each card in a suit is represented by the following dimension indices.
- 0 = the 2 card
- 1 = the 3 card
- 2 = the 4 card
- 3 = the 5 card
- 4 = the 6 card
- 5 = the 7 card
- 6 = the 8 card
- 7 = the 9 card
- 8 = the 10 card
- 9 = the jack
- 10 = the queen
- 11 = the king
- 12 = the ace
- All the number cards are worth their face value (i.e., a 3 of diamonds is worth 3).
- All face cards are worth 10.
- An ace is worth either 1 or 11. Your final-score calculation must be able to handle this correctly for both the dealer and each player.
- A random-number generator must be used to select the suit and the card in the suit.
Once a card and suit are selected, the program should check if the value of that array element is a “space.”- If the array element = “space,” set the element equal to an integer, identifying the dealer or the player.
- 0 = dealer
- 1 = player 1
- 2 = player 2
- 3 = player 3
- 4 = player 4
- If the array element ! = “space,” then the random-number and card- checking process should repeat until a “card” or an array element is selected that is = “space.”
- If the array element = “space,” set the element equal to an integer, identifying the dealer or the player.
- Once a card is drawn during a game, it cannot be drawn again.
- If the user inputs to play the game, the next decision should be 1, 2, 3, or 4 players.
- The game ends when each player has 3 cards.
- The display should show each player’s (and the dealer’s) hand and update the display after each round of card draws.
- At the end of a game, the an updated balance.