Question

bject Oriented Programming Home My units BISY2003/1SY2006/ISY211 12 2020 Assessments A4 (Practical 40%) estion 4 yet wered Cr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Sharp Program:

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

namespace Library
{
//Book Class
class Book
{
private String title;
private String author;
private int numPages;
private double price;

//Constructor
public Book(String t, String a, int np, double p)
{
title = t;
author = a;
numPages = np;
price = p;
}

//ToString method
public String ToString()
{
return title + "*" + author + "*" + numPages + "*" + price;
}
}

class Program
{
//Main method
static void Main(string[] args)
{
String tTitle, tAuthor;
int tNumPages;
double tPrice;
int cnt = 1;

//Opening file for writing
using (StreamWriter writer = new StreamWriter("Books.txt"))
{
while (true)
{
Console.Write("\nEnter title of the book(000 to end): ");
tTitle = Console.ReadLine();

//Checking title
if (tTitle.Equals("000") == true)
{
break;
}

Console.Write("Enter author of the book: ");
tAuthor = Console.ReadLine();

Console.Write("Enter number of pages in the book: ");
tNumPages = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter price of the book: ");
tPrice = Convert.ToDouble(Console.ReadLine());

//Creating Book object
Book b = new Book(tTitle, tAuthor, tNumPages, tPrice);

//Writing to file
writer.WriteLine(cnt.ToString()+"*"+b.ToString());
cnt++;
}
}

Console.ReadLine();
}
}
}
____________________________________________________________________________________________

Sample Run:

Books.txt x Program.cs 1* How to Talk to anyone*Leil Lowndess*450*18.54 2*My Autobiography*Tim Henry*189*5.98 X х III file://

Add a comment
Know the answer?
Add Answer to:
bject Oriented Programming Home My units BISY2003/1SY2006/ISY211 12 2020 Assessments A4 (Practical 40%) estion 4 yet...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT