0% found this document useful (0 votes)
47 views

Program C#

The document defines a Book class with properties for book name, author, category, and price. It then reads book data from a file, creates Book objects, and adds them to a list. It calculates the total library price and price per category, outputting the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Program C#

The document defines a Book class with properties for book name, author, category, and price. It then reads book data from a file, creates Book objects, and adds them to a list. It calculates the total library price and price per category, outputting the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication1

class Program

static void Main(string[] args)

Dictionary<string, double> dictionar = new Dictionary<string, double>();


string[] books = File.ReadAllLines("TextFile1.txt");

List<Book> listOfBooks = new List<Book>();

for (int i = 0; i < books.Length; i++)

string[] elements = books[i].Split(new char[] { ',' },

StringSplitOptions.RemoveEmptyEntries);
Book numeBook = new Book(elements[0], elements[1], elements[2],

double.Parse(elements[3]));

listOfBooks.Add(numeBook);

double pretTotalLibrarie = 0;

for (int i = 0; i < listOfBooks.Count; i++ )

Console.Write("Carte" + i.ToString() + " - " + listOfBooks[i].ToString());

Console.WriteLine();

pretTotalLibrarie = pretTotalLibrarie + listOfBooks[i].ValPret();


if (dictionar.ContainsKey(listOfBooks[i].NumCategorie()))

dictionar[listOfBooks[i].NumCategorie()] = dictionar[listOfBooks[i].NumCategorie()]

+ listOfBooks[i].ValPret();

else

dictionar.Add(listOfBooks[i].NumCategorie(), listOfBooks[i].ValPret());

Console.WriteLine("inventar librarie = " + pretTotalLibrarie);


for (int i = 0; i < dictionar.Count; i++)

Console.WriteLine(dictionar.Keys.ElementAt(i) + " = " + dictionar.Values.ElementAt(i));

Console.Read();

}
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1

class Book

private string numeCarte;

private string numeAutor;

private string numeCategorie;

private double valoarePret;

public Book()
{

public Book(string carte, string autor, string categorie, double pret)

numeCarte = carte;

numeAutor = autor;

numeCategorie = categorie;

valoarePret = pret;

public override string ToString()

{
return "Titlu : " + numeCarte + ", Autor: " + numeAutor + ", Categorie: " +

numeCategorie + ", Pret: " + valoarePret.ToString();

public double ValPret()

return valoarePret;

public string NumCategorie()

return numeCategorie;

You might also like