forum.ge
reklama
FORUM.GE წესები  · დახმარება  · ძებნა  · წევრები  · კალენდარი  · ფოსტა  · ჩატი
  გამოხმაურება · ახალი თემა · ახალი გამოკითხვა

> დამეხმარეთ C++ ამოცანაზე
toko7777
Newbie


*
ჯგუფი: Registered
წერილები: 1
წევრი No.: 227254
რეგისტრ.: 21-December 16

გამოგზავნილია: 21 Dec 2016, 21:20  #49543289      · პროფილი · პირადი მიმოწერა · ჩატი · ელფოსტა
mogesalmebit gtxovt damexmarot am programis dawerashi
* * *
Define the Book class with the following fields: a title, author list (being a list of strings, empty by
default), an edition year being an integer number and a unique positive sequential book number
(computed for each book using a static field counting all the books). Implement the following
public methods of the class:
• the constructor with parameters for a title and an edition year of the book (setting the book
number to the next free value),
• the copy-constructor and the assignment operator (ensuring that the books have different
sequential numbers),
• the destructor,
• getTitle, setTitle, getYear, setYear, getNumber methods,
• addAuthor – with an author as a parameter, adding a new author of the book as the last one,
• removeAuthor – with an author as a parameter, removing the author from the book's author
list (or throwing an error if the author is not in the author list),
• getAuthorCount – returning the number of authors of the book,
• the indexing operator ([]) – returning the book's author placed within the author list on the
position given as a parameter (1 means the first author, 2 means the second one, etc., an
error should be thrown for the position exceeding the number of authors),
• the shift operator (<<) – printing the book's title, year, its number, and the list of all its
authors.
Write a program which tests all the class capabilities, i.e. the following code should be enabled:
Book book1(“C++ Primer”, 2010);
cout << book1.getNumber(); //should be 1
cout << book1.getYear(); //should be 2010
book1.addAuthor(“Lipman”);
book1.addAuthor(“Lajoie”);
cout << book1.getAuthorCount(); //should be 2
book1[1] = “Lippman”; //changes the first author
cout << book1; //should print:
//Title: C++ Primer
//Year: 2010
//Number: 1
//Authors: Lippman, Lajoie
Book book2(“The C Programming”, 1985);
book2.addAuthor(“Kernignan”);
book2.addAuthor(“Smith”);
book2.addAuthor(“Ritchie”);
book2.setTitle(“The C Programming Language”);
cout << book2[2]; //should be Smith
book2.removeAuthor(“Smith”);
cout << book2[2]; //should be Ritchie
cout << book2.getAuthorCount(); //should be 2
cout << book2; //should print:
//Name: The C Programming Language
//Year: 1985
//Number: 2
//Authors: Kernighan, Ritchie
Book book3(book2);
cout << book3; //should print:
//Name: The C Programming Language
//Year: 1985
//Number: 3
//Authors: Kernighan, Ritchie
book3 = book1;
cout << book3.getTitle(); //should be C++ Primer
cout << book3.getNumber(); //should be 3

მიმაგრებული ფაილი ( Number of downloads: 18 )
მიმაგრებული ფაილი  test__3_.pdf
0 წევრი ათვალიერებს ამ თემას (0 სტუმარი და 0 უჩინარი წევრი)
0 წევრი:
Topic Options გამოხმაურება · ახალი თემა · ახალი გამოკითხვა

 



ფორუმის სერვერების განთავსებას და ინტერნეტთან კავშირს უზრუნველყოფს: CLOUD9
[ Script Execution time: 0.0149 ]   [ 13 queries used ]   [ GZIP Disabled ]