SlideShare uma empresa Scribd logo
1 de 4
BookStore.CS


using   System;
using   System.Collections.Generic;
using   System.Linq;
using   System.Text;
using   System.Collections;

namespace ConsoleApplication1
{

    public delegate void EditionHandler();
    public class Book
    {
        public string Title;        // Title of the book.
        public string Author;       // Author of the book.
        public string BookType;     //Type of Book
        public decimal Price;       // Price of the book.
        public bool Paperback;      // Is it paperback?
        public EditionHandler AddEdition;
        public Book(string title, string author, decimal price, bool
paperBack)
        {
            Title = title;
            Author = author;
            Price = price;
            Paperback = paperBack;

          }

          public void ShowEditions()
          {
              if (AddEdition != null)
                  AddEdition();
          }

    }



    public delegate void PrintBook(Book book);
    public class BookDB
    {
        // List of all books in the database:
        ArrayList list = new ArrayList();

        // Add a book to the database:
        public void AddBook(string title, string author, decimal price, bool
paperBack)
        {
            list.Add(new Book(title, author, price, paperBack));
        }

          // Call a passed-in delegate on each paperback book to process it:
          public ArrayList List
{
            get
            {
                  return list;
            }
        }

        public void PrintPaperBackBooks()
        {
            decimal TotalPrice = 0, AveragePrice = 0, ctr = 0;
            foreach (Book b in list)
            {

                  if(b.Paperback)
                  {
                  Console.WriteLine(" Book Name {0}", b.Title);
                  Console.WriteLine(" Book Author {0}", b.Author);
                  Console.WriteLine(" Book Price {0:C}", b.Price);
                  Console.WriteLine(" Book Paperback {0}", b.Paperback);
                  Console.WriteLine("n");
                  TotalPrice = TotalPrice + b.Price;
                  ctr++;
                  }

            }
            AveragePrice = TotalPrice / ctr;

            Console.WriteLine("Average of Paper Back Books is : {0:C}",
AveragePrice);
        }

        public void PrintAllBooks()
        {
            foreach (Book b in list)
            {
                Console.WriteLine(" Book   Name {0}", b.Title);
                Console.WriteLine(" Book   Author {0}", b.Author);
                Console.WriteLine(" Book   Price {0}", b.Price);
                Console.WriteLine(" Book   Paperback {0}", b.Paperback);
                Console.WriteLine("n");
            }
        }


    }

}
Program.cs
using   System;
using   System.Collections.Generic;
using   System.Linq;
using   System.Text;

namespace ConsoleApplication1
                                       {
    class Program
    {
        static void Main(string[] args)
        {
            BookDB bookDB = new BookDB();

              // Initialize the database with some books:
              AddBooks(bookDB);
              printHeader();
              bookDB.PrintPaperBackBooks();

              Book b1 = (Book)bookDB.List[0];
              b1.AddEdition = Edition1;
              b1.AddEdition += Edition2;
              b1.AddEdition += Edition3;

              b1.ShowEditions();



          }

        static void printHeader()
        {
            Console.WriteLine("Printing Book Details as on {0}",
DateTime.Now.ToString("dd-MMM-yyyy"));
            Console.WriteLine("n");


          }
          static void AddBooks(BookDB bookDB)
          {
              bookDB.AddBook("The C Programming Language",
                 "Brian W. Kernighan and Dennis M. Ritchie", 19.95m, true);
              bookDB.AddBook("The Unicode Standard 2.0",
                 "The Unicode Consortium", 39.95m, true);
              bookDB.AddBook("The MS-DOS Encyclopedia",
                 "Ray Duncan", 129.95m, false);
              bookDB.AddBook("Dogbert's Clues for the Clueless",
                 "Scott Adams", 12.00m, true);
          }

          static void Edition1()
          {
              Console.WriteLine("Edition1 added");
          }
static void Edition2()
        {
            Console.WriteLine("Edition2 added");
        }
        static void Edition3()
        {
            Console.WriteLine("Edition3 added");
        }

    }
}

Mais conteúdo relacionado

Mais procurados

Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Paris Kafka Meetup - How to develop with Kafka
Paris Kafka Meetup - How to develop with KafkaParis Kafka Meetup - How to develop with Kafka
Paris Kafka Meetup - How to develop with KafkaFlorian Hussonnois
 
Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...
Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...
Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...DataStax Academy
 
Mongo sharding
Mongo shardingMongo sharding
Mongo shardingNik Kul
 
杨卫华:微博cache设计浅谈
杨卫华:微博cache设计浅谈杨卫华:微博cache设计浅谈
杨卫华:微博cache设计浅谈Leechael
 
What's new in Ansible 2.0
What's new in Ansible 2.0What's new in Ansible 2.0
What's new in Ansible 2.0Allan Denot
 
Drinking from the firehose: Logging at scale with ELK
Drinking from the firehose: Logging at scale with ELKDrinking from the firehose: Logging at scale with ELK
Drinking from the firehose: Logging at scale with ELKCteodorski
 
Shell Tips & Tricks
Shell Tips & TricksShell Tips & Tricks
Shell Tips & TricksMongoDB
 
Statim, time series interface for Perl.
Statim, time series interface for Perl.Statim, time series interface for Perl.
Statim, time series interface for Perl.Thiago Rondon
 
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19MoscowJS
 
Kubernetes Nedir?
Kubernetes Nedir?Kubernetes Nedir?
Kubernetes Nedir?AnkaraCloud
 
A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupSudar Muthu
 
JEP 286 Local-Variable Type Inference - Ted's Tool Time
JEP 286 Local-Variable Type Inference - Ted's Tool TimeJEP 286 Local-Variable Type Inference - Ted's Tool Time
JEP 286 Local-Variable Type Inference - Ted's Tool TimeTed Vinke
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015
The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015
The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015Johan
 

Mais procurados (18)

Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Paris Kafka Meetup - How to develop with Kafka
Paris Kafka Meetup - How to develop with KafkaParis Kafka Meetup - How to develop with Kafka
Paris Kafka Meetup - How to develop with Kafka
 
Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...
Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...
Cassandra Day NY 2014: Apache Cassandra & Python for the The New York Times ⨍...
 
Mongo sharding
Mongo shardingMongo sharding
Mongo sharding
 
杨卫华:微博cache设计浅谈
杨卫华:微博cache设计浅谈杨卫华:微博cache设计浅谈
杨卫华:微博cache设计浅谈
 
What's new in Ansible 2.0
What's new in Ansible 2.0What's new in Ansible 2.0
What's new in Ansible 2.0
 
Comets notes
Comets notesComets notes
Comets notes
 
Node36
Node36Node36
Node36
 
Drinking from the firehose: Logging at scale with ELK
Drinking from the firehose: Logging at scale with ELKDrinking from the firehose: Logging at scale with ELK
Drinking from the firehose: Logging at scale with ELK
 
Shell Tips & Tricks
Shell Tips & TricksShell Tips & Tricks
Shell Tips & Tricks
 
Statim, time series interface for Perl.
Statim, time series interface for Perl.Statim, time series interface for Perl.
Statim, time series interface for Perl.
 
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
"Работа с утечками в V8", Роман Кривцов, MoscowJS 19
 
Kubernetes Nedir?
Kubernetes Nedir?Kubernetes Nedir?
Kubernetes Nedir?
 
A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
 
JEP 286 Local-Variable Type Inference - Ted's Tool Time
JEP 286 Local-Variable Type Inference - Ted's Tool TimeJEP 286 Local-Variable Type Inference - Ted's Tool Time
JEP 286 Local-Variable Type Inference - Ted's Tool Time
 
Exec Sp
Exec SpExec Sp
Exec Sp
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015
The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015
The Directions Pipeline at Mapbox - AWS Meetup Berlin June 2015
 

Destaque

All .net Interview questions
All .net Interview questionsAll .net Interview questions
All .net Interview questionsAsad Masood Qazi
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#Shahzad
 
Top 100 .Net Interview Questions and Answer
Top 100 .Net Interview Questions and AnswerTop 100 .Net Interview Questions and Answer
Top 100 .Net Interview Questions and AnswerVineet Kumar Saini
 
C# console programms
C# console programmsC# console programms
C# console programmsYasir Khan
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programsMukesh Tekwani
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#Svetlin Nakov
 
How the Best of the Best are Becoming The Best with Values-Based Leadership
How the Best of the Best are Becoming The Best with Values-Based LeadershipHow the Best of the Best are Becoming The Best with Values-Based Leadership
How the Best of the Best are Becoming The Best with Values-Based LeadershipWiley
 
Red r assignment(1)
Red r assignment(1)Red r assignment(1)
Red r assignment(1)savisthri
 
Tech week 1 assignment
Tech week 1 assignmentTech week 1 assignment
Tech week 1 assignmentsierra98
 
Confidentiality security week 1 assignment
Confidentiality security week 1 assignmentConfidentiality security week 1 assignment
Confidentiality security week 1 assignmentDIKRIS4595
 
Tech week 1 assignment
Tech week 1 assignmentTech week 1 assignment
Tech week 1 assignmentsierra98
 
Edutech week 1 assignment
Edutech week 1 assignmentEdutech week 1 assignment
Edutech week 1 assignmentHeather Kimble
 
Week 1 assignment
Week 1 assignmentWeek 1 assignment
Week 1 assignmentanarce6217
 
Tech week 1 assignment Wendy
Tech week 1 assignment WendyTech week 1 assignment Wendy
Tech week 1 assignment Wendysierra98
 
Gameplay assignment week 1
Gameplay assignment week 1Gameplay assignment week 1
Gameplay assignment week 1SeanClarke1
 
Tech week 1 assignment
Tech week 1 assignmentTech week 1 assignment
Tech week 1 assignmentsierra98
 

Destaque (20)

C# interview
C# interviewC# interview
C# interview
 
All .net Interview questions
All .net Interview questionsAll .net Interview questions
All .net Interview questions
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
Top 100 .Net Interview Questions and Answer
Top 100 .Net Interview Questions and AnswerTop 100 .Net Interview Questions and Answer
Top 100 .Net Interview Questions and Answer
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
C# console programms
C# console programmsC# console programms
C# console programms
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programs
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#
 
How the Best of the Best are Becoming The Best with Values-Based Leadership
How the Best of the Best are Becoming The Best with Values-Based LeadershipHow the Best of the Best are Becoming The Best with Values-Based Leadership
How the Best of the Best are Becoming The Best with Values-Based Leadership
 
Red r assignment(1)
Red r assignment(1)Red r assignment(1)
Red r assignment(1)
 
Tech week 1 assignment
Tech week 1 assignmentTech week 1 assignment
Tech week 1 assignment
 
Confidentiality security week 1 assignment
Confidentiality security week 1 assignmentConfidentiality security week 1 assignment
Confidentiality security week 1 assignment
 
Tech week 1 assignment
Tech week 1 assignmentTech week 1 assignment
Tech week 1 assignment
 
Edutech week 1 assignment
Edutech week 1 assignmentEdutech week 1 assignment
Edutech week 1 assignment
 
Week 1 assignment
Week 1 assignmentWeek 1 assignment
Week 1 assignment
 
Dq 2 week 3 tcp freindly
Dq 2 week  3 tcp freindlyDq 2 week  3 tcp freindly
Dq 2 week 3 tcp freindly
 
Tech week 1 assignment Wendy
Tech week 1 assignment WendyTech week 1 assignment Wendy
Tech week 1 assignment Wendy
 
Gameplay assignment week 1
Gameplay assignment week 1Gameplay assignment week 1
Gameplay assignment week 1
 
Tech week 1 assignment
Tech week 1 assignmentTech week 1 assignment
Tech week 1 assignment
 
R bernardino hand_in_assignment_week_1
R bernardino hand_in_assignment_week_1R bernardino hand_in_assignment_week_1
R bernardino hand_in_assignment_week_1
 

Mais de application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Assignment
AssignmentAssignment
Assignment
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
C # test paper
C # test paperC # test paper
C # test paper
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 

Último

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 

Último (20)

YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 

Week 1 assignment q2

  • 1. BookStore.CS using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { public delegate void EditionHandler(); public class Book { public string Title; // Title of the book. public string Author; // Author of the book. public string BookType; //Type of Book public decimal Price; // Price of the book. public bool Paperback; // Is it paperback? public EditionHandler AddEdition; public Book(string title, string author, decimal price, bool paperBack) { Title = title; Author = author; Price = price; Paperback = paperBack; } public void ShowEditions() { if (AddEdition != null) AddEdition(); } } public delegate void PrintBook(Book book); public class BookDB { // List of all books in the database: ArrayList list = new ArrayList(); // Add a book to the database: public void AddBook(string title, string author, decimal price, bool paperBack) { list.Add(new Book(title, author, price, paperBack)); } // Call a passed-in delegate on each paperback book to process it: public ArrayList List
  • 2. { get { return list; } } public void PrintPaperBackBooks() { decimal TotalPrice = 0, AveragePrice = 0, ctr = 0; foreach (Book b in list) { if(b.Paperback) { Console.WriteLine(" Book Name {0}", b.Title); Console.WriteLine(" Book Author {0}", b.Author); Console.WriteLine(" Book Price {0:C}", b.Price); Console.WriteLine(" Book Paperback {0}", b.Paperback); Console.WriteLine("n"); TotalPrice = TotalPrice + b.Price; ctr++; } } AveragePrice = TotalPrice / ctr; Console.WriteLine("Average of Paper Back Books is : {0:C}", AveragePrice); } public void PrintAllBooks() { foreach (Book b in list) { Console.WriteLine(" Book Name {0}", b.Title); Console.WriteLine(" Book Author {0}", b.Author); Console.WriteLine(" Book Price {0}", b.Price); Console.WriteLine(" Book Paperback {0}", b.Paperback); Console.WriteLine("n"); } } } }
  • 3. Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { BookDB bookDB = new BookDB(); // Initialize the database with some books: AddBooks(bookDB); printHeader(); bookDB.PrintPaperBackBooks(); Book b1 = (Book)bookDB.List[0]; b1.AddEdition = Edition1; b1.AddEdition += Edition2; b1.AddEdition += Edition3; b1.ShowEditions(); } static void printHeader() { Console.WriteLine("Printing Book Details as on {0}", DateTime.Now.ToString("dd-MMM-yyyy")); Console.WriteLine("n"); } static void AddBooks(BookDB bookDB) { bookDB.AddBook("The C Programming Language", "Brian W. Kernighan and Dennis M. Ritchie", 19.95m, true); bookDB.AddBook("The Unicode Standard 2.0", "The Unicode Consortium", 39.95m, true); bookDB.AddBook("The MS-DOS Encyclopedia", "Ray Duncan", 129.95m, false); bookDB.AddBook("Dogbert's Clues for the Clueless", "Scott Adams", 12.00m, true); } static void Edition1() { Console.WriteLine("Edition1 added"); }
  • 4. static void Edition2() { Console.WriteLine("Edition2 added"); } static void Edition3() { Console.WriteLine("Edition3 added"); } } }