|
C++
- Assignment 1: The basics of writing functions, loops, doing some basic Math and returning values. Download this code and follow the instructions.
- Math
- C Strings
- Assignment Strings,Chars,Ints and Math I'm tweaking Project Euler #11. Just sum all of the digits from the problem. Your assignment. Calculate the greatest sum, difference and product of any two adjacent double digit (there's the catch!)ints in this problem.
- Pointers
Dealing with Memory I
- Reference Variables and Pointers
-
- Assignment: Write 3 functions involving arrays. In all cases, use pointer notation.
(ie *myarray++ not myarray[i] )
- 1) should
cout all elements in array
- 2) should initialize all elements to random numbers between 1 and 100 of an array that is passed using pointer notation.
- 3) should take two paramaters (both array pointers) and should copy the elements of the first array into the second array. Yes you can assume they have the same length
Two Dimensional Arrays in C++
download some sample code and and assingment on two dimensional arrays
- Assignment : A local zoo wants to keep track of how many pounds of food each of its three monkeys eat each day during a typical week. Write a program that stores this information in a two dimensional 3 * 7 array, where each each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey. Then it should create a report that includes the following information
- Average amount of food eaten per day by the whole family of monkeys
- Least amount of food eaten by any 1 monkey during the course of the week.
- Greatest amount of food eaten by any 1 monkey during the course of the week
Vectors :: PrimeFactorization
Assignment: Create a function that uses a vector to calculate the prime factorization of number. Don't lose this code as we might use it in an upcoming project.
C++ Classes
- C++ Classes Compared to Java Classes
- Assignment: Your First Assignment using a C++ class
Below is a partially created class called 'vWrapper' as it largely functions as a wrapper class for a single private variable (a vector of ints). Download the code start playing around with it. The assignment instructions are in the comments in the code.
- vWrapper class
- Dynamic Memory Allocation
- Here's some source code that demonstrates how you allocate and (de-allocate) dynamic memory.
- Assignment 1: Write a function that dynamiclly allocates an array of integers. The function should accept an int parameter and, using
new , should create an array of ints with random numbers. Return a pointer to this new array.
- Strings
- Useful Links for this project : cctype | cstring
Assignment: Write a class called Scstring (for 'super C-string)with the following functions: uppper ,lower , reverseCase , mostFrequentDigit , sumOfDigits .
- The upper function should accept a pointer to a C-string as an argument. It should step thorugh each character in the string, converting it to uppercase. The same idea for
lower .
- Like upper and lower,
reverseCase should also accept a pointer to a string. As it steps through the string, it should test each caracter to determine whether it is upper- or lowercase and it should switch the case.
mostFrequentDigit does exactly what it sounds like it does.
sumOfDigits :: self explanatory
Copy Constructors
- link 1: When you can use the default copy constructor
- link 2 & link 3:
- When you should write your own copy constructor:
- If the class does not have pointer variables with dynamically allocated memory, then one need not worry about defining a copy constructor
-
Here is some source code demonstrating a copy constructor.
- Classes and operator overloading
- Static Members
- Account Assignment: Write a class that represents an Account at a bank (either savings or checking). The class should
- have a default constructor Account()
- at least 1 non default constructor Account(double b);
- have the following public methods and fields
- double getBalance()
- void setBalance(double to);
- void setinterestRate(double to);
- int getAccountNum()
- static int accountNumber
- private fields
- double balance ;
- double interestRate
- int accountNum
- char * accountOwner
- Bank
- Create a Bank class that holds a vector full of accounts. This class should implement the following functionality
- calculate the sum of all money in the bank
- close a bank account (remove from vector)
- add a new bank account
- print out a comma separated list of all account owner names
- Ineritance in C++
- Inheritance Example Code(Taken from http://www.cplusplus.com/doc/tutorial/inheritance/)
Although constructors and destructors of a base class are not inherited themselves, default constructor (i.e., its constructor with no parameters) and its destructor are always called when a new object of a derived class is created or destroyed."
- Extend the Account Class
write the following subclasses of Account
- CheckingAccount . This class should provide public means of accessing and mutating the following private variables
- int checksWritten
- int checksBounced
- bool is_overdrawn
- SavingsAccount . This class should provide public means of accessing and mutating the following private variables
- int minimum_balance
- int is_underDrawn
Credit
- 1) This code was taken from Tony Gaddis' Starting out with C++: From Control Structures through Objects. This example code is provided solely for my students.
|