Answer to Question #188991 in C# for santhosh asrith

Question #188991

 Create a Class named BooksDemo accepts and displays the details of books using multidimensional array.

BooksDemo

-colName:string[4] = {"BookTitle", "Author", "Publisher", "Price"}

-bookDetails: string[2,4]

+Main(args: string[])


1
Expert's answer
2021-05-07T07:28:32-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


namespace C_SHARP
{






    class BooksDemo
    
    {
        private string []colName = {"BookTitle", "Author", "Publisher", "Price"};
        private string [,]bookDetails=new string[2,4];
        /// <summary>
        /// Constructor
        /// </summary>
        public BooksDemo() {
            
        }
        /// <summary>
        /// Read Books
        /// </summary>
        public void ReadBooks()
        {
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < colName.Length; i++)
                {
                    Console.Write("Enter {0}: ", colName[i]);
                    bookDetails[j, i] = Console.ReadLine();
                }
                Console.Write("\n");
            }
        }
        /// <summary>
        /// Display Books
        /// </summary>
        public void DisplayBooks()
        {
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < colName.Length; i++)
                {
                    Console.Write("{0}: {1}\n", colName[i], bookDetails[j, i]);
                }
                Console.Write("\n");


            }
        }


        static void Main(string[] args)
        {
            BooksDemo booksDemo = new BooksDemo();
            booksDemo.ReadBooks();
            booksDemo.DisplayBooks(); ;
           
            Console.ReadKey();
        }


    }
}

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
New on Blog
APPROVED BY CLIENTS