User Tools

Site Tools


haas:spring2024:cprog:projects:cpp1

Corning Community College

CSCS1320 C/C++ Programming

PROJECT: C Plus Plus: Inheritance (CPP1)

OBJECTIVE

Investigate, author, and continue to develop an understanding of C++, this time extending that study onto inheritance.

A core part of this project is in being active on discord and asking questions to hone your understanding.

EDIT

You will want to go here to edit and fill in the various sections of the document:

CPPX

C++ compiler

To compile a C++ script, you can use g++ -o (new name) (uncompiled name).cpp

For example, to compile a script called script.cpp:

g++ -o script script.cpp
common file extensions

C++ file extensions:

  • .cpp
  • .CC
  • .cxx

C++ header file extensions

  • .hpp
  • .h
  • hxx

The recommended extensions are .cpp and .hpp

  • The selection of a file extensions usually comes down to preference or versions of software you're using

The output of the compiled code comes out as a .o file

Preproccesed C++ Source Files have a .ii file extension

Classes

A class in C++ is a user-defined type or data structure declared with any of the keywords class, struct, or union

  • By default access to members of a C++ class declared with the keyword class is private. The private members are not accessible outside the class; they can be accessed only through member functions of the class
  • The public members form an interface to the class and are accessible outside the class.

For example:

// Define the class
class MyClass {
    // Class members go here
};
Member Functions

Member functions are the functions, which have their declaration inside the class definition and works on the data members of the class. The definition of member functions can be inside or outside the definition of class.

  • if its defined outside the class, use the scope resolution :: operator along with class name along with function name.

defined inside:

class Cube
{
    public:
    int side;
    int getVolume()
    {
        return side*side*side;      //returns volume of cube
    }
};

defined outside:

class Cube
{
    public:
    int side;
    int getVolume();
}

int Cube :: getVolume()
{
    return side*side*side;
}
Constructor

A constructor in C++ is a special ‘MEMBER FUNCTION’ having the same name as that of its class which is used to initialize some valid values to the data members of an object. It is executed automatically whenever an object of a class is created.

default constructor

class Line
{
 public:
 int size;

Line()
{
 size=30;
}
};
/////////////
int main()
{
 //default constructor called when object is created
 Line l;
}

parameter constructor

class ABC
{
     private:
        int x,y;
     public:
        ABC ()       //constructor 1 with no arguments
       {
            x = y = 0;
        }
        ABC(int a)    //constructor 2 with one argument
       {
             x = y = a;
        }
        ABC(int a,int b)    //constructor 3 with two argument
        {
              x = a; 
              y = b;
        }
};
/////////////////
int main()
{
     ABC cc1; //constructor 1
     ABC cc2(10); //constructor 2
     ABC cc3(10,20); //constructor 3
     return 0:
}
Destructor

A destructor is a member function that is invoked automatically when the object goes out of scope or is explicitly destroyed by a call to delete or delete[]. A destructor has the same name as the class and is preceded by a ~. Example:….

  • the destructor for class String is declared: ~String()
class String
{
    public:
        String(const char* ch);  // Declare the constructor
        ~String();               // Declare the destructor
    private:
        char* _text{nullptr};
};

// Define the destructor.
String::~String()
{
    // Deallocate the memory that was previously reserved for the string.
    delete[] _text;
}
Member Data

A data member in C++ is a non-function member of a class (class, struct, or union).

class C {
    // In C++, this is a "data member".
    int x;
};
Access Control

Access controls enable you to separate the public interface of a class from the private implementation details and the protected members that are only for use by derived classes.

Access control helps prevent you from using objects in ways they weren't intended to be used. This protection is lost when you make explicit type conversions.

Public

Class members declared as public can be used by any function.

For example:

class MyClass {
public:
    int publicMember;
};
Private

Class members declared as private can be used only by member functions and friends (classes or functions) of the class.

For example:

class MyClass {
private:
    int privateMember;
};
Protected

Class members declared as protected can be used by member functions and friends (classes or functions) of the class. Additionally, they can be used by classes derived from the class.

For example:

class MyClass {
protected:
    int protectedMember;
};

Objects

In C++, an object is created from a class.

class CLASSNAME {
   Public:
      int sumthinNumb;
}
/////////////////////////
int main() 
{
   CLASSNAME objname;
   objname.sumthinNumb = 12834589028390458;
   cout << objname.sumthinNUmb << "/n";

   return 0;
}
}
 

SUBMISSION

To be successful in this project, the following criteria (or their equivalent) must be met:

  • Project must be submit on time, by the deadline.
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
  • Executed programs must display in a manner similar to provided output
    • output formatted, where applicable, must match that of project requirements
  • Processing must be correct based on input given and output requested
  • Output, if applicable, must be correct based on values input
  • Code must be nicely and consistently indented
  • Code must be consistently written, to strive for readability from having a consistent style throughout
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
      • Sufficient comments explaining the point of provided logic MUST be present
  • No global variables (without instructor approval), no goto statements, no calling of main()!
  • Track/version the source code in your lab46 semester repository
  • Submit a copy of your source code to me using the submit tool by the deadline.

Submit Tool Usage

Let's say you have completed work on the project, and are ready to submit, you would do the following:

lab46:~/src/SEMESTER/DESIG/PROJECT$ submit DESIG PROJECT file1 file2 file3 ... fileN

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

RUBRIC

I'll be evaluating the project based on the following criteria:

104:cppX:final tally of results (104/104)
*:cppX:activity on discord related to project [13/13]
*:cppX:questions on discord related to project over at least 3 days [13/13]
*:cppX:content published to project documentation page [13/13]
*:cppX:content organized on project documentation page [13/13]
*:cppX:code compiles, builds with no warning or error [13/13]
*:cppX:code utilizes inheritance [13/13]
*:cppX:instantiates and performs some task [13/13]
*:cppX:committed project related changes to semester repo [13/13]

Pertaining to the collaborative authoring of project documentation

  • each class member is to participate in the contribution of relevant information and formatting of the documentation
    • minimal member contributions consist of:
      • near the class average edits (a value of at least four productive edits)
      • near the average class content change average (a value of at least 128 bytes (absolute value of data content change))
      • near the class content contribution average (a value of at least 1kiB)
      • no zero-sum commits (adding in one commit then later removing in its entirety for the sake of satisfying edit requirements)
    • adding and formatting data in an organized fashion, aiming to create an informative and readable document that anyone in the class can reference
    • content contributions will be factored into a documentation coefficient, a value multiplied against your actual project submission to influence the end result:
      • no contributions, co-efficient is 0.50
      • less than minimum contributions is 0.75
      • met minimum contribution threshold is 1.00

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 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
  • Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction
haas/spring2024/cprog/projects/cpp1.txt · Last modified: 2024/04/08 11:32 by 127.0.0.1