﻿part 1.

#include <iostream>

using namespace std;

int main()
{
	int playerScore;
	float studentHeight;
	double pi = 3.14159;

	cout << "Enter the players score: " << endl;
	cin >> playerScore;

	cout << "Enter the student's height: " << endl;
	cin >> studentHeight;

	cout << "Enter pi to 5 digits: " << endl;
	cin >> pie;

	cout << playerScore << endl;
	cout << studentHeight << endl;
	cout << pi << endl;

	return 0;
}

Part 2.

#include <iostream>

using namespace std;

int main()
{
	float cRadius, cArea, tArea, tBase, tHeight;

	cout << "\nEnter the radius of circle: " << endl;
	cin >> cRadius;

	cout << "\nEnter the base of triangle: " << endl;
	cin >> tBase;
	cout << "\nEnter the Height of triangle: " << endl;
	cin >> tHeight;

	tArea = tBase * tHeight / 2;

	cArea = 3.14 * cRadius * cRadius;

	cArea = cArea - tArea;

	cout << "Area of circle: " << cArea;


	return 0;
}

Part 3.

#include <iostream>

using namespace std;

int main()
{
	int quantity, price, total;
	float discount;

	price = 30;
	
	//\x9C is '£'
	cout << "\r\n Price per tonne = \x9C 30" << endl;
	cout << "\r\n Please enter quantity amount: " << endl;
	cin >> quantity;

	if (quantity <= 4)
	{
		total = quantity * price;
		cout << quantity << " tonnes of gravel = " << "\x9C " << total << endl;
	}

	if (quantity >= 5 && quantity <= 8)
	{
		discount = 2;
		total = ((100 - discount) / 100) * (quantity * price);
		cout << quantity << " tonnes of gravel = " << "\x9C " << total << endl;
	}

	if (quantity >= 9 && quantity <= 40)
	{
		discount = 4;
		total = ((100 - discount) / 100) * (quantity * price);
		cout << quantity << " tonnes of gravel = " << "\x9C " << total << endl;
	}

	if (quantity > 40)
	{
		discount = 6;
		total = ((100 - discount) / 100) * (quantity * price);
		cout << quantity << " tonnes of gravel = " << "\x9C " << total << endl;
	}

	return 0;
}


Part 4.

#include <iostream>
#include <string>
#include <time.h>
#include "functions.h"

using namespace std;

int main()
{
	int size;

	printf("\r\n enter size of rows: ");
	scanf_s("%d", &size);

	for (int rows = 1; rows <= size; rows++) //rows
	{
		for (int collumn = 1; collumn <= size; collumn++) // collumns
		{
			if (rows == collumn || collumn == (size + 1) - rows)
				printf("*");
			else
				printf(" ");
		}
		printf("\r\n");
	}

	return 0;
}
part 6.
-----------------
items.cpp
-----------------

#include "Stock.h"
#include "Items.h"
#include <iostream>

using namespace std;

Product::Product()
{
	Pen = new Stock(0.80, "Pen");
	Ruler = new Stock(0.80, "Ruler");
	Rubber = new Stock(0.80, "Ruler");
	Pencil = new Stock(0.80, "Ruler");
	Sharpener = new Stock(0.80, "Ruler");
}

Product::~Product()
{
	delete Pen;
	delete Ruler;
	delete Rubber;
	delete Pencil;
	delete Sharpener;
}

Stock * Product::GetItem(int itemNumber)
{
	switch (itemNumber)
	{
	case 0:
		return Pen;
		break;
	case 1:
		return Ruler;
		break;
	case 2:
		return Rubber;
		break;
	case 3:
		return Pencil;
		break;
	case 4:
		return Sharpener;
		break;
	default:
		//Unrecognised index
		return nullptr;
		break;
	}
------------------
Stock.cpp
------------------
#include <iostream>
#include "Stock.h"

using namespace std;

double Stock::GetItemPrice(void)
{
	cout << "Please enter price: " << endl;
	cin >> _itemPrice;
	return _itemPrice;
}

string Stock::ItemName(void)
{
	return _itemName;
}

bool Stock::SetItemPrice(double itemPrice)
{
	if (itemPrice < 0.0)
	{
		return false;
	}
	else
	{
		_itemPrice = itemPrice;
		return true;
	}
}

--------------------
Source.cpp
--------------------
#define    _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "Items.h"
#include "Stock.h"

using namespace std;

int main()
{
	
	Product * P = new Product();

	Stock * Pen = P->GetItem(0);



	delete P;

	return 0;
}

--------------------
Items.h
--------------------
#pragma once

#include "Stock.h"

class Product
{
private:
	//Attributes
	Stock * Pen;
	Stock * Ruler;
	Stock * Rubber;
	Stock * Pencil;
	Stock * Sharpener;

public:
	//Constructor
	Product();
	//Destructor
	~Product();

	//Properties

	//Methods

	Stock* GetItem(int itemNumber);
};

--------------------
Items.h
--------------------
#pragma once
#include <string>

using namespace std;

class Stock
{
private:
	//Attributes
	int _tax;
	int _numberSold;
	double _totalItemProfit;
	double _itemPrice;
	string _itemName;

public:
	//Constructor
	Stock(double itemPrice, string itemName);
	~Stock();

	//Properties

	double GetItemPrice(void);
	string ItemName(void);

	//Methods
	bool SetItemPrice(double itemPrice);
};


part 7.

#include <iostream>
#include <cstdlib> 
#include <ctime>
#include <string>

using namespace std;

void slotMachine();
void combos(int x);
void GetScore();
int nums[3];

int main()
{
	string play = "Yes";
	//loops until anything but Yes.
	while (play == "Yes")
	{
		slotMachine();
		cout << endl;
		GetScore();
		cout << "Spin again? ('Yes/No') " << endl;
		cin >> play;
		cout << " +-----------------------------+ " << endl;
	}

	return 0;
}

void slotMachine()
{
	//Stores 3 randomNum into nums[].
	time_t theTime;
	srand((unsigned)time(&theTime));

	cout << "You've spun: ";

	for (int i = 0; i <3; i++)
	{
		int randomNum = (rand() % 5) + 1;
		nums[i] = randomNum;
		combos(nums[i]);
	}
}

void combos(int x)
{
	switch (x)
	{
	case 1: cout << " Seven ";
		break;
	case 2: cout << " Bar ";
		break;
	case 3: cout << " Bell ";
		break;
	case 4: cout << " Plum ";
		break;
	case 5: cout << " Cherries ";
		break;
	case 6: cout << " Orange ";
		break;
	}
}

void GetScore()
{
	int score = 0;
	int isfive = 0;
	
	//Loops to check if matching.
	for (int i = 0; i < 3; i++)
	{
		for (int o = 0; o < 3; o++)
		{
			if (i + 1 == o)
			{
				i++;
			}
			if (nums[o] == nums[i + 1])
			{
				score++;
				if (nums[o] == 5)
				{
					isfive++;
				}
			}
		}
		if (i == 2)
		{
			break;
		}
	}
	
	//Displaying the score/reward if matches.
	if (score > 0)
	{
		if (isfive > 0)
		{
			if (score = 1 && isfive == 2)
			{
				cout << "Jackpot! You win 2000:" << endl;
			}
			else if (score = 2 && isfive == 1)
			{
				cout << "You win 100!" << endl;
			}
		}
		if (score > 1 && isfive < 1)
		{
			cout << "You win 20!" << endl;
		}
		else if (score > 0 && isfive < 1)
		{
			cout << "You win 10!" << endl;
		}
	}
	else
	{
		cout << "You win 0!" << endl;
	}
}

Part 8.

battleships.cpp
#include <string>
#include <iostream>
#include "battleships.h"

using namespace std;

const int rows = 8;
const int collumn = 8;
int maxShips = 4;
int matrix[rows][collumn];

//function to clear the arrays.
void ClearMatrix()
{
	for (int i = 0; i < rows; i++)
	{
		for (int o = 0; o < collumn; o++)
		{
			matrix[i][o] = 0;
		}
	}
}

void DisplayMatrix()
{
	for (int i = 0; i < rows; i++)
	{
		for (int o = 0; o < collumn; o++)
		{
			cout << matrix[i][o] << " ";
		}
		cout << endl;
	}
}

void setShip()
{
	int s = 0;
	while (s < maxShips)
	{
		int x = rand() % rows;
		int y = rand() % collumn;
		if (matrix[x][y] != 1)
		{
			s++;
			matrix[x][y] = 1;
		}
	}
}
int numOfShips()
{
	int c = 0;

	for (int i = 0; i < rows; i++)
	{
		for (int o = 0; o < collumn; o++)
		{
			if (matrix[i][o] == 1)
				c++;
		}
	}
	return c;
}

bool Attack(int x, int y)
{
	if (matrix[x][y] == 1)
	{
		matrix[x][y] == 2;
		return true;
	}
	return false;
}
----------------------------------------------
Ships.cpp
#include <string>
#include <iostream>
#include <time.h>
#include "battleships.h"

using namespace std;


int main()
{
	//Clearning & displaying the matrix
	//Randomly place ships inside the matrix
	srand(time(NULL));
	ClearMatrix();
	setShip();
	int pos1, pos2;
	char prompt;
	while (1)
	{
		cout << "Please input location: ";
		cin >> pos1 >> pos2;
		if (Attack(pos1, pos2))
			cout << "You got me!" << endl;
		else
			cout << "Sorry no ship at that position!" << endl;
		cout << "Number of ships left: " << numOfShips() << endl;
		cout << "Surrender (y/n)?";
		cin >> prompt;
		if (prompt == 'y')
			break;
	}
	cout << "Game over!" << endl;
	DisplayMatrix();


	return 0;
}
----------------------------------------------
battleships.h
#pragma once

void ClearMatrix();
void DisplayMatrix();
void setShip();
int numOfShips();
bool Attack(int x, int y);

