C# – Object Oriented Programming – Lab 5

You are required to develop an App, which acts as a fashion advisor. The program will have a form where you can type in the colour of your top, your pants and your shoes. The program will then give advice on whether the colours match. The program can use any feedback mechanism desirable.

The rules the program should implement are as follows:

The program only understands the colours black, red, blue, green, pink, brown or orange. The program should generate an error if any other colour is typed.

Black top, pants and shoes are fine
Brown shoes, blue pants and any coloured top is fine
Black shoes, blue pants and any coloured top is fine
Brown shoes, brown pants and blue top is fine
Brown shoes, black pants and red top is fine
Black shoes, brown pants and blue top is fine
Black shoes, black pants and blue top is fine
Any coloured shoes with orange pants are fine
Green shoes with any coloured pants and any coloured top, so long as its not red are fine.
All pink is fine.
Never have pink shoes with green pants, but pink shoes with red pants are fine.

Anything other combinations, the program should indicate that the particular combination of colours is not recommended.

Here’s my solution using a WPF app:

This is what the app looks like:

This is my code:
Continue reading

C# – Object Oriented Programming – Lab 4

Here is the scenario we want to test:

– Write a “if else” statement that checks to see if bx and by are INSIDE the box. If the point (bx,by) is inside the box, print “Inside” otherwise print “Not inside”. (Hint use && in your answer)

– Write a “if else” statement that checks to see if bx and by are OUTSIDE the box. If the point (bx, by) is outside the box, print “Outside” otherwise print “Not outside”. (Hint use && in your answer)

– Test your IF statements with different values of bx and by

– See if you can make these if statements do the opposite by using the ! (not)
Values for the points:

x1,y1 = 100,100

x2, y2 = 120,150

bx, by = 115, 120
Here’s my solutions for it:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
namespace lab4

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.Title = "The Console - Lab 4 - IF statements";

            bool returnTrue;

            bool notInside;
            float x1, y1, x2, y2, bx, by, cx, cy, dx, dy;

            x1 = 100;

            y1 = 100;

            x2 = 120;

            y2 = 150;

            bx = 115;

            by = 120;

            cx = 50;

            cy = 300;

            dx = 115;

            dy = 120;
            if (bx > x1 && bx < x2 && by > y1 && by < y2)

            {

                returnTrue = true;

                Console.WriteLine("Is bx,by inside the box = " + returnTrue);

            }

            else

            {

                returnTrue = false;

                Console.WriteLine("Is bx,by inside the box = " + returnTrue);

            }
            if (cx < x1 || cx > x2 || cy < y1 || cy > y2)

            {

                returnTrue = true;

                Console.WriteLine("Is cx,cy outside the box = " + returnTrue);

            }

            else

            {

                returnTrue = false;

                Console.WriteLine("Is cx,cy outside the box = " + returnTrue);

            }
            Console.WriteLine();

            if (dx > x1 && dx < x2 && dy > y1 && dy < y2)

            {

                returnTrue = true;

                notInside = !returnTrue;

                Console.WriteLine("Is dx,dy inside the box = " + returnTrue);

                Console.WriteLine("Is dx,dy inside the box (not operator test) = " + notInside);

            }

            else

            {

                returnTrue = false;

                Console.WriteLine("Is bx,by inside the box = " + returnTrue);

            }
            Console.ReadKey();

        }

    }

}

C# – Object Oriented Programming – Lab 2 (Equation of a Line)

The equation of a line is given as: y = mx +c. Write a program that asks the user for the start and end points of a line and calculates values for m and c:

m = The slope of the line (y2 – y1) / (x2 – x1)
c = The intercept (where the line intersects the y axis (i.e. Where x = 0)

Here’s my solution for it:
Continue reading

Quadratic Equation

C# – Object Oriented Programming – Lab 1 (Roots of a quadratic equation)

So I thought I’d upload some of the C# Object Oriented Programming labs I was given in my Computer Games studies and my solutions for them. Here’s the first one:

Lab1
Create a Windows Console application, with a number of variables:
a, b c (floats)
x1 and x2 (floats)
hasRoots (boolean)

The purpose of the program is to calculate the roots of the quadratic equation using the quadratic formula:

Here’s my solution for it:

Continue reading