C++ Exam2 Flashcards
Class Specification File
Example:
// class specifiation file #ifndef RECTANGLE\_H #define RECTANGLE\_H
// class declaration class Rectangle { private: double length; double width; public: bool setLength(double); bool setWidth(double); double getLength(); double getWidth(); double calcArea(); }; #endif
Class Function Implementation File
Example
// class function implementation file #include "Rectangle.h"
bool Rectangle::setLength(double len)
{
bool validData = true;a
if (len >= 0)
length = len;
else
validData = false;
return validData;
}
bool Rectangle::setWidth(double w)
{
bool validData = true;
if (w >= 0)
width = w;
else
validData = false;
return validData;
}
double Rectangle::getLength()
{
return length;
}
double Rectangle::getWidth()
{
return width;
}
double Rectangle::calcArea()
{
return length * width;
}
API stands for Application Programming Interface
In computer programming, an application programming interface is a set of subroutine definitions, communication protocols, and tools for building software. In general terms, it is a set of clearly defined methods of communication among various components.
A good API makes it easier to develop a computer program by providing all the building blocks, which are then put together by the programmer.
An API may be for a web-based system, operating system, database system, computer hardware, or software library.
A set of functions and procedures allowing the creation of applications that access the features or data of an operating system, application, or other service.
JSON
JavaScript Object Notation and is basically a way of representing data that looks like JavaScript objects.
documentation
In computer hardware and software product development, documentation is the information that describes the product to its users. … The term is also sometimes used to mean the source information about the product contained in design documents, detailed code comments, white papers, and blackboard session notes.
bubble sort
bubble sort - ascending or descending - swaps adjacent elements - first pass -
inefficient for large arrays because of the repeated swaps and passes
void sort(int num[], int x)
{
int temp;
bool swap;
do
{ swap = false;
for (int y = 0; y < (x-1); y++) // one minus the actual size because the
if statement will compare the next highest value
{
if (num[y] > num[y+1])
{
temp = num[y];
num [y] = num[y+1];
num[y+1] = temp;
swap = true;
}
}
}while(swap);
}
struct defined and intialized
struct Date
{
int month,
day,
year;
};
Date JasonBday = {1, 29, 1981); // Date variable defined and initialized
structure declaration
// structure declaration
struct Employee {
string name;
int vacationDays,
daysUsed;
Employee(string n = “”, int d = 0) // Default constructor
{
name = n;
vacationDays = 10;
daysUsed = d;
}
};
passing structures to functions
preferable to pass by constant reference to functions
void showIte(const InvItem &); // Prototype
void showItem(const InvItem &item) // Header
simple PayRoll struct
struct PayRoll // Initialization list (set of memory locations)
{
int empNumber;
string name;
double hours,
payRate,
grossPay;
};
Payroll deptHead, foreman, associate; // Define variables of the Payroll
structure
PayRoll struct continued
deptHead.empNumber = 475;
foreman.empNumber = 897;
associate.empNumber = 729;
cout << “Enter the employee’s name: “; // example of input into a member
variable of the Payroll struct
getline(cin, associate.name);