User Tools

Site Tools


Sidebar

projects

wcp1 (due 20240124)
pct0 (bonus; due 20240125)
pct1 (bonus; due 20240125)
abc0 (due 20240131)
pct2 (due 20240131)
wcp2 (due 20240131)
gtf0 (due 20240207)
pct3 (bonus; due 20240207)
wcp3 (due 20240207)
dtr0 (due 20240214)
pct4 (due 20240214)
wcp4 (due 20240214)
bwp1 (bonus; due 20240228)
mmf0 (due 20240228)
pct5 (bonus; due 20240228)
wcp5 (due 20240228)
cnv0 (due 20240306)
gfo0 (due 20240306)
pct6 (due 20240306)
wcp6 (due 20240306)
cnv1 (due 20240313)
fwg0 (due 20240313)
pct7 (bonus; due 20240313)
wcp7 (due 20240313)
fwg1 (due 20240320)
pct8 (due 20240320)
wcp8 (due 20240320)
pct9 (bonus; due 20240327)
wcp9 (due 20240327)
bwp2 (bonus; due 20240410)
fwg2 (due 20240410)
fwg3 (due 20240410)
gfo1 (due 20240410)
pctA (due 20240410)
wcpA (due 20240410)
cpp0 (due 20240417)
pctB (bonus; due 20240417)
wcpB (due 20240417)
cpp1 (due 20240424)
pctC (due 20240424)
wcpC (due 20240424)
pctD (bonus; due 20240501)
wcpD (bonus; due 20240501)
gfo2 (due 20240508)
pctE (bonus; due 20240508)
wcpE (bonus; due 20240508)
EoCE (due 20240516)
haas:spring2024:cprog:projects:oop0

Corning Community College

CSCS1320 C/C++ Programming

PROJECT: Object-Oriented Programming (OOP0)

Objective

Explore the basics of C++ programming, specifically the creation of classes and instantiation of objects, and the implementation of a simple program that has and uses a class.

The idea is to demonstrate your skills gained throughout the semester, by harnessing new concepts and problem solving experiences to delve into this new area of the course: C++ and object-oriented programming.

C++

Backstory of C++ Programming language

Backstory and motivation of its creation

In the 1960s-1990s many computer programming languages were being created for different purposes, but most of them had flaws. Some languages were easy to understand, but lacked the depth to accomplish more difficult tasks. Others had this capability, but were large, abstract, and very difficult to learn, thus leading people to create more with the goal of having a language that was not too complex, but could effectively complete difficult tasks. This eventually led to a C language that was good for low level programming, and a SIMULA language that had a class system. C++ language was the creation of Bjarne Stroustrup that combined these two.

Differences between C and C++ language

The main difference between the two is that C is a procedural programming language, whereas C++ is a hybrid language that can perform both procedural and object oriented programming. C supports built in data types, whereas C++ can support both built-in and user defined data types. C has 32 keywords, whereas C++ has 63 keywords, and C++ supports far more things in general than C. From a security standpoint, C does not support encapsulation so data can be manipulated by outside code meanwhile C++ supports encapsulation so the data is hidden.

Why C++ is still being updated today

C++ is still updated today because it is still so widely used today, due to its speed, programming capability, and its continued popularity in being used (even if a superior language did come out computer scientists would still have to learn that new language, and languages already written in C++ would still be written in C++).

Common uses of C++ in current times

C++ is most notably used in the creation of high performance programs, such as video games, operating systems, and the Google Chrome and Firefox web browsers.

Cool bug facts:

C++ is a play on the ++ increment operator in C language.

C++ was originally called 'The New C'.

C++ has influenced other programming languages such as C# and Java.

OOP

Object Oriented Programming refers to a type of programming that uses objects that contain both data and functions. This is opposed to procedural programming, which is about writing procedures or functions that perform operations. OOP has several advantages over Procedural Programming which include:

  • OOP provides a management structure for programs.
  • OOP helps make code easier to maintain, modify and debug.
  • OOP makes it possible to create reusable applications with less code and a shorter development time.

Classes

Classes are effectively user defined data types. They make it easier to work with data by providing users with the ability to create constructors, destructors, member data, member functions, and more.

Member Data

In C++, you can define data inside of classes for the sake of using them with member functions. Access specifiers can be used to determine where these variables can be called from, and which functions can call them. (This is further described down below)

Methods (Member Functions)

Methods are functions that belong to a class. The two ways to define a function that belongs to a class are inside the class definition and outside the class definition. In order to define a method outside the class definition, you must first declare it inside the class. You can then define your function outside of the class by specifying the name of the class and following it with the “::” operator. These functions are meant to be used alongside member data.

Constructors

Constructors are functions that are called when an object is created. They can be used with or without parameters, similarly to any other type of function. They do not return any values.

Destructors

Destructors are special functions that are called in any of the below conditions:

(1) the function ends (2) the program ends (3) a block containing local variables ends (4) a delete operator is called

They are meant to be used when a pointer is used in a class, or when memory has been dynamically allocated, in order to prevent memory leakage.

Classes as Value/Reference types

C++ classes are by default value types. Value types typically deal with memory or layout control, whereas, reference types are related to base classes and virtual functions for polymorphic purposes. A difference between the two types, is that value types are copyable, meaning, there is a copy constructor and copy assignment operator. Reference types on the other hand, make the class non-copyable, using a virtual destructor. Changing the class type is something that is done by the user/programmer, and is done by disabling the copy constructor and copy assignment operator. In short value types are about creating two values that can each be modified, whereas, reference types are more about identity.

Access Control

Public

Public members can be accessed in any part of the program.

Private

Private members can only be accessed by members of the same class.

Protected

Protected members can be accessed by members of the same class, friend classes, and derived classes

Structs vs Classes

Struct members are public by default. Class members are private by default.

Inheritance

Single inheritance is when one class inherits directly from one other class. This is typical for most classes. Public inheritance does not change in subclasses from the parent class. Protected inheritance refers to when anything higher than protected will be protected. Both public and protected properties will be protected in a subclass. Private inheritance takes this a step further as all three inheritance types will be made private in a subclass.

Objects

Instances of a class. Creating an object of a class works almost exactly like initializing any fundamental type; simply specify the the type name, followed by your variable's name. Objects are introduced by declarations.

Program

Write a program that creates one or more of the following classes:

  • rectangle
  • triangle
  • trapezoid

That contains, in addition to at least 2 constructors (parameterless, and a parametered), the following public member functions:

  • getLength()
  • getWidth()
  • setLength()
  • setWidth()
  • area()
  • perimeter()

Store length, width, and any other pertinent core values as private, accessible only from the public member functions.

Have a main() function that instantiates an instance of your chosen shape class, and runs that instantiated object through a range of tests demonstrating the class works as intended (likely also prompting the user to input values to configure the attributes of the object).

References

Submission

I'll be looking for the following:

104:oop0:final tally of results (104/104)
*:oop0:no compiler messages, program compiles and runs without issue [52/52]
*:oop0:specified functionality is implemented [52/52]

Additionally:

  • Solutions not abiding by SPIRIT of project will be subject to a 50% overall deduction
  • Solutions not utilizing descriptive why and how COMMENTS will be subject to a 50% overall deduction
  • Solutions not utilizing INDENTATION to promote scope and clarity will be subject to a 50% overall deduction
  • Solutions lacking ORGANIZATION and are not easy to read (within 90 char width) are subject to a 50% overall deduction
haas/spring2024/cprog/projects/oop0.txt · Last modified: 2023/04/10 23:26 by 127.0.0.1