Practice Exercises C# Sharp - Learn to program with performing exercises C# Sharp

Practice Exercises C# Sharp

Learn to program with performing exercises C# Sharp

Square - Practice Exercises C# Sharp
Practice Exercises C# Sharp4,85320940

Square - Practice Exercises C# Sharp


Lesson 6:

Object oriented programming


Exercise 6.5:

Square


Objetive:

Complete the project named "Shapes" (january 8th), adding a class named "Square" to it. For each square, we will store its starting X and Y coordinates (the upper left corner, already stored as a "Location") and the length of its side.

You will have to create:
- A suitable constructor, to assign starting values to X, Y and the side. (2 points)
- A Move method, to change X and Y coordinates. (1 point)
- A Scale method, to change its side (for example, a scale factor of 2 would turn a side of 3 into 6). (1 point)
- A method ToString, to return a string with its data (for example: "Corner (10,5), side 7". (1 point)
- Redefine "GetPerimeter" and "GetArea", so that they return the correct values (2 points).

- Another point corresponds to the attributes and the overall structure.

- The remaining 2 points correspond to the test from "Main"

You must deliver a ZIP file containing the entire project.


Source Code:


using System;
namespace shapes
{
    class Square : Shape
    {
        Location l = new Location();

        public Square(double x, double y, double side)
        {

            l.SetX(x);
            l.SetY(y);
            l.SetSide(side);
        }

        public void Move(double x, double y)
        {
            l.SetX(x);
            l.SetY(y);
        }

        public void Scale(int factor)
        {
            l.SetSide(l.GetSide() * factor);
        }

        public string ToString()
        {
            return "Corner (" + l.GetX() / 2 + "), side " + l.GetSide();
        }
    }
}
Exercisey 6.5

Share Now:







Privacy Policy:



Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.

Cookies

This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.