SlideShare une entreprise Scribd logo
1  sur  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");
        }

    }
}

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Plus 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
 

Dernier

NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Dernier (20)

NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

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"); } } }