Answer to Question #180968 in C# for Muhammmad Arfan

Question #180968

Suppose a publisher is going to market its book and audiocassette. Write

C# windows application with following tasks.

1. Publication class with data member title, price

2. two derived classes book(Page_count) and tape (playing time)

3.Every class should have getdata() and putdata() member function

Write the main() function to test the program.


1
Expert's answer
2021-04-13T09:18:58-0400
//Publication.cs

using System;


namespace MyApplication
{
    class Publication
    {
        string title = "Default Title";
        int price = 10;


        public string getTitle()
        {
            return title;
        }


        public int getPrice()
        {
            return price;
        }


        public void setTitle(string value)
        {
            title = value;
        }


        public void setPrice(int value)
        {
            price = value;
        }


    }
}

//Book.cs

using System;


namespace MyApplication
{
    class Book : Publication
    {
        int pageCount = 200;


        public int getPageCount()
        {
            return pageCount;
        }


        public void setPageCount(int value)
        {
            pageCount = value;
        }
    }
}

//Tape.cs

using System;


namespace MyApplication
{
    class Tape : Publication
    {
        int playingTime = 45;


        public int getPlayingTime()
        {
            return playingTime;
        }


        public void setPlayingTime(int value)
        {
            playingTime = value;
        }
    }
}

//Program.cs

using System;


namespace MyApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Book myBook = new Book();
            Tape myTape = new Tape();


            myBook.setTitle("Pride and Prejudice");
            myBook.setPrice(20);
            myBook.setPageCount(280);


            myTape.setTitle("Michael Jackson - Thriller");
            myTape.setPrice(15);
            myTape.setPlayingTime(50);


            Console.WriteLine("Title: " + myBook.getTitle() + ", $" + myBook.getPrice() + ", Number of pages: " + myBook.getPageCount());
            Console.WriteLine("Title: " + myTape.getTitle() + ", $" + myTape.getPrice() + ", Playing time: " + myTape.getPlayingTime() + " min");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS