/cplusplus_exercises

A small repo containing programming exercises completed in C++

Primary LanguageC++

Repository for Sample C++ Exercises - Gregory Kelleher

This repository contains some sample C++ exercises I've done

Contents

  • Lab 1

    • Exercise 1: A program that inputs three integers from the keyboard, and prints the sum, average, product, smallest and largest of these numbers.

    • Exercise 2: A program that reads in two integers and determines and prints if the first is a multiple of the second.

    • Exercise 3: A program that inputs a five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each.

    • Exercise 4: A program that will determine if a department-store customer has exceeded the credit limit on a charge account.

    • Exercise 5: A program that checks if a number is prime and prints all prime number between 1 and 5000.

  • Lab 2

    • Exercise 1: A program that takes two integers as input and swaps their values.

    • Exercise 2: A program that finds the greatest common divisor (GCD) of two integers.

    • Exercise 3: A program that simulates the rolling of two dice based on user input and calculates the sum of the two values returned. The program also prints out the percentage of times each possible total value occurs.

    • Exercise 4: A program the initialises two character arrays with two strings, prints out their length, prints out the combined length and then prints out the combined string.

    • Exercise 5: A program that prints out c-style character strings based on two methods. The first using the array indexing operator and the second using a pointer to traverse the characters of the string.

  • Lab 3

    • Exercise 1: A program that allows the user to input a sequence of doubles and then prints that sequence in reverse. The length of the sequence is specified at run-time.

    • Exercise 2: A program that extends the functionality of the above, such that it keeps reading the sequence until it reads -1. The program does not have a pre-defined fixed sequence length.

    • Exercise 3: A program that uses structs to read in the name and age of people and then prints them out in reverse. The program stores these details in an array of structs.

    • Exercise 4: A program that creates a static link list of three people's names.

    • Exercise 5: A program that separates the above program's functionality into an implementation and header file, to be compiled independent of the main program.

    • Exercise 6: A program that extends the functionality of the customer's API such that it provides all of the functionality necessary to construct a linked list of people (of arbitrary length); inputed by the user.

  • Lab 4

    • Exercise 1: A program using C++ classes that simulates the rolling of two dice based on user input and calculates the sum of the two values returned. The class also permits a die of any positive number of sides to be represented. The program also has a constraint that a die should have no less than four sides. If the user inputs a die of less than 4 sides, the program defaults to 6 sides. Lastly the program prints out the percentage of times each possible total value occurs.

    • Exercise 2: A program using C++ exercises that performs complex number arithmetic.

    • Exercise 3: A program that reimplements the functions from the above program using overloading operators.