C++ Programming Assignment 5: Defining and Using Classes, Assignments of Computer Science

A programming assignment for creating a c++ class, including class definition, member functions, and constructors. Students will learn how to instantiate an object of the class and perform operations such as setting the day, printing the day, and returning the next and previous day. The document also includes instructions for downloading and compiling the provided daytype stub.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-vqd
koofers-user-vqd 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:
Sec: 07/03/2008
Programming Assignment #5
Defining and Using C++ Classes
Recall that the two structured data types we have studied so far are arrays, which
have elements all of the same type, and structures, which have elements of
differing types. Another structured data type is a class, which is specifically
designed to combine data and functions in a single unit. A class is a collection of a
fixed number of components. The components of a class are called the members
of the class. If a member of a class is a variable, you define it just like any other
variable, but you cannot initialize it at definition. If a member of a class is a
function, you typically use the function prototype to define that member. Member
functions can directly access any data member of the class without passing that
data member as an argument.
No memory is allocated in a class definition. Instead, memory is allocated when
the class is instantiated (an object is created). Additionally, the semicolon (;) is
part of the syntax at the end of the class definition. The members of a class are
classified into three categories: private, public, and protected. By default, all
members of a class are private. Private members cannot be accessed outside of the
class. A public member is accessible outside the class.
Objectives
In this assignment you will learn how to define a class and declare and use
instances of the class.
After completing this assignment, you will be able to:
Write a header and source file that contains a class definition.
Instantiate an object of a class.
Work with multiple files for a single programming project.
Instructions
Part 1: Download, compile and run the DayType stub
In order to make getting started with this assignment a little easier, I have
provided 3 files for you that take care of some of the details you will need when
creating a class. The files are called DayType.h, DayType.cpp and
DayTypeTest.cpp. You should download these files, create a project in the IDE
of your choice, and then add and make sure you can compile and run the stub
pf2

Partial preview of the text

Download C++ Programming Assignment 5: Defining and Using Classes and more Assignments Computer Science in PDF only on Docsity!

Name: Sec: 07/03/

Programming Assignment

Defining and Using C++ Classes

Recall that the two structured data types we have studied so far are arrays, which have elements all of the same type, and structures, which have elements of differing types. Another structured data type is a class, which is specifically designed to combine data and functions in a single unit. A class is a collection of a fixed number of components. The components of a class are called the members of the class. If a member of a class is a variable, you define it just like any other variable, but you cannot initialize it at definition. If a member of a class is a function, you typically use the function prototype to define that member. Member functions can directly access any data member of the class without passing that data member as an argument. No memory is allocated in a class definition. Instead, memory is allocated when the class is instantiated (an object is created). Additionally, the semicolon (;) is part of the syntax at the end of the class definition. The members of a class are classified into three categories: private, public, and protected. By default, all members of a class are private. Private members cannot be accessed outside of the class. A public member is accessible outside the class.

Objectives

In this assignment you will learn how to define a class and declare and use instances of the class. After completing this assignment, you will be able to:  Write a header and source file that contains a class definition.  Instantiate an object of a class.  Work with multiple files for a single programming project.

Instructions

Part 1: Download, compile and run the DayType stub In order to make getting started with this assignment a little easier, I have provided 3 files for you that take care of some of the details you will need when creating a class. The files are called DayType.h, DayType.cpp and DayTypeTest.cpp. You should download these files, create a project in the IDE of your choice, and then add and make sure you can compile and run the stub

program. The DayType class I provide doesn't do anything yet, you will have to fill in the details for your part of the assignment. Part 2: Implement the DayType class For your assignment, you should implement the following functionality for the DayType class. The class DayType should store the day, such as Sun for Sunday, Mon for Monday, etc. (use a string or maybe even better an enumerated type see pg. 420). The program should be able to perform the following operations on an object of type DayType (these will all be member functions you need to implement):

  1. Set the day (setter method)
  2. Print the day
  3. Return the day (getter method)
  4. Return the next day
  5. Return the previous day Your should also implement the appropriate constructors for you DayType class (at a minimum a default constructor and a constructor accepting a single parameter indicating the initial day should be implemented).

Assignment 5 Finished

You have now completed Assignment 5. If your program compiles and runs correctly and you have successfully uploaded your source file to the eCollege online submission site, then you are done.