Lab3 - Array and Function - Division of Applied Science and Technology Community College of City University AST21105 Object-Oriented Programming Design

Lab3 - Array and Function - Division of Applied Science and...

This preview shows page 1 - 3 out of 11 pages.

Division of Applied Science and Technology, Community College of City University AST21105 Object-Oriented Programming & Design Page 1 of 11 AST21105 Object-Oriented Programming & Design Lab 3 – Array and Function A. Submission Details In this lab, you are required to submit ONE C++ program to solve the given problem shown in the section “Master Mind”. To make the program implementation easier, you are suggested to write your program using Visual Studio .NET instead of doing it directly using paper & pencil. After you have completed the implementation, submit your program file (i.e. MasterMind.cpp for this lab) using the electronic “drop-box” in Canvas within two weeks after your lab section is conducted. For details, please refer to the following: You are reminded to double-check your solution to verify everything is correct before submission. You are also required to put your name and student ID at the beginning of your source file. Important: You are only able to submit your work once. B. Objective The objective of this lab is to help you get familiar with arrays and functions (i.e. a construct similar to methods in Java) that you have learned in Java last year. Also, you will be introduced to the difference between Java and C++ so as to speed you up your learning process of C++. The first part of this lab is meant to be a simple review of array and function declarations using Microsoft Visual Studio .NET. The second part of this lab is practical task that allow you to use all the techniques introduced (i.e. arrays and functions). Tuesday sections by 19:00 on 7 February 2017 (Tuesday) Wednesday sections by 19:00 on 8 February 2017 (Wednesday) Thursday sections by 19:00 on 9 February 2017 (Thursday)
Image of page 1
Division of Applied Science and Technology, Community College of City University AST21105 Object-Oriented Programming & Design Page 2 of 11 C. Review 1. Declaration of arrays An array is a collection of variables that are of the same type. Possible types used are: Integer data types short, int, long Floating point data types float, double Character type char Boolean type bool User-defined type All other types Comparing to Java, C++ offers the flexibility to declare an array using new or not using new keyword (Recall that array in Java has to be declared using new keyword.). In this lab, we only focus on declaring array not using new . Syntax: // Declare an array named <name of variable> of size <size> in type <type> <type> <name of variable>[<size>]; where <type> could be in one of the following types: short , int , long , float , double , char , bool or user-defined data type Important note: - <size> has to be a constant, it cannot be a variable. - The initial values of the array are garbage (Again, this is another feature that is different from Java. Recall, Java automatically initializes an array of int type to 0, array of double type to 0.0, array of boolean type to false, but this is not the case in C++.)
Image of page 2
Image of page 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture