Practice Exercises C# Sharp

Practice Exercises C# Sharp

Learn to program performing exercises with C# Sharp

12 Lessons C# Sharp with the Solutions - 228 Exercises C# Sharp with the solutions
For Beginners, Intermediates and Advanceds


The human knowledge belongs to the world
¡The infomation should be free!

5 Estrellas - 9986Total Votos

Catalog - Practice Exercises C# Sharp


Lesson 7:

More on classes


Exercise 7.7:

Catalog


Objetive:

Create the classes diagram and then, using Visual Studio, a project and the corresponding classes for a catalog utility:

It will be able to store information about music files, films and computer programs.
For each item, it must store: name, code, category and size. For films it must also hold the director, the main actor and the main actress. For music files, the singer and the length (in seconds).
For music and movies it must have a method "Play" (not implemented yet) and also a method "RetrieveInformation", which will (in a later version) connect to an internet server to get information about it.
Use inheritance if needed. In "Main", create arrays of each kind of object.



Google Ads


Source Code:


using System;
namespace Catalog
{
    class TestItem
    {
        static void Main()
        {
            Film[] myFilms = new Film[3];
            Music[] myMusic = new Music[3];
            ComputerProgram[] myComputerProgram = new ComputerProgram[3];
        }
    }

    public class Item
    {
        protected string name;
        protected string code;
        protected string category;
        protected string size;

        public Item()
        {
        }
        public Item(string name, string code, string category, string size)
        {
            this.name = name;
            this.code = code;
            this.category = category;
            this.size = size;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        public string Category
        {
            get { return category; }
            set { category = value; }
        }
        public string Size
        {
            get { return size; }
            set { size = value; }
        }
    }

    public class Film : Item
    {
        protected string director;
        protected string mainActor, mainActress;

        public Film()
        {

        }
        public Film(string director, string mainActor, string mainActress)
        {
            this.director = director;
            this.mainActor = mainActor;
            this.mainActress = mainActress;
        }

        public string Director
        {
            get { return director; }
            set { director = value; }
        }
        public string MainActor
        {
            get { return mainActor; }
            set { mainActor = value; }
        }
        public string MainActress
        {
            get { return mainActress; }
            set { mainActress = value; }
        }

        public void Play()
        {

        }
        public void RetrieveInformation()
        {

        }
    }

    public class Music : Item
    {
        protected string singer;
        protected int length;

        public Music()
        {

        }
        public Music(string singer, int length)
        {
            this.singer = singer;
            this.length = length;
        }

        public string Singer
        {
            get { return singer; }
            set { singer = value; }
        }
        public int Lenght
        {
            get { return length; }
            set { length = value; }
        }

        public void Play()
        {

        }
        public void RetrieveInformation()
        {

        }
    }

    public class ComputerProgram : Item
    {

    }
}

                
Exercisey 7.7

Google Ads







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.