예제 #1
0
        static void Main(string[] args)
        {
            string numLivrosSTR;
            int    numLivrosINT;
            string titulo, autor;

            Book[] books;


            Console.WriteLine("Quantos livros tem?");
            numLivrosSTR = Console.ReadLine();
            numLivrosINT = Convert.ToInt32(numLivrosSTR);

            books = new Book[numLivrosINT];

            for (int i = 0; i < numLivrosINT; i++)
            {
                string title, author;
                Book   b;

                Console.WriteLine("\nQual o título do livro " + (i + 1) + "?");
                title = Console.ReadLine();

                Console.WriteLine("E o autor?");
                author = Console.ReadLine();

                b        = new Book(title, author);
                books[i] = b;
            }

            foreach (Book b in books)
            {
                Console.WriteLine("");
                Console.WriteLine($"Título: {b.GetTitle()}");
                Console.WriteLine("Comprimento: {0}", b.GetTitleLength());
                Console.WriteLine("Autor:" + b.GetTitle());
            }


            Console.WriteLine(Book.GetTotalBooks());
        }
예제 #2
0
        static void Main(string[] args)
        {
            //declaring variables
            int nBooks;

            Book[] bookerinos;
            //asking for the number of books
            Console.WriteLine("insert the number of books");
            nBooks     = Convert.ToInt32(Console.ReadLine());
            bookerinos = new Book[nBooks];

            //for each book
            for (int i = 0; i < nBooks; i++)
            {
                //declare variables
                string title, author;
                Book   b;
                //ask for title
                Console.Write("Title: ");
                title = Console.ReadLine();
                //ask for author
                Console.Write("Auhor: ");
                author = Console.ReadLine();
                //create a book object
                b = new Book(title, author);
                //save title in array
                bookerinos[i] = b;
            }
            //for each book specified
            foreach (Book b in bookerinos)
            {
                //show title
                Console.WriteLine($"Titulo:{b.GetTitle()}");
                //show lenght
                Console.WriteLine("Comprimento: {0}", b.GetTitleLength());
                //show author
                Console.WriteLine("Author: " + b.GetAuthor());
            }

            Console.WriteLine(Book.GetTotalBooks());
        }