65 746
Assignments Done
99,3%
Successfully Done
In October 2018

Answer to Question #34912 in C# for Tahzeeb Akram

Question #34912
increment the number of pages of a book by the number of pages enter by the user using operator overloading
Expert's answer
using System;


class Book
{
private string name;
private int pages;

public Book(string name, int pageCount)
{
this.name = name;
this.pages = pageCount;
}

public int GetPageCount()
{
return pages;
}

public static Book operator + (Book book, int pagesCount)
{
book.pages += pagesCount;
return book;
}
}


class Program
{
public static void Main()
{
Book boo = new Book("The Witch", 352);

Console.WriteLine(boo.GetPageCount());
Console.Write("Enter the number of additional pages: ");

int additionalPageCount = Convert.ToInt32(Console.ReadLine());
boo += additionalPageCount;

Console.WriteLine(boo.GetPageCount());
}
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions