LearnFrenzy
Sign in Take a free test

Classes and Objects · Exercise 4 of 4

Classes and Objects Class Programs

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

C++ programs built around well-designed classes. Write each one yourself first, then open the solution – every solution was compiled and run, and the output shown is the real output.

Question 1 Medium

Write a Date class that validates day/month/year (including leap years), and a member function that returns the next day; test month and year boundaries.

Question page & discussion
Question 2 Medium

Write a Fraction class that always stores fractions in lowest terms with a positive denominator, supports + and *, and prints with operator<<.

Question page & discussion
Question 3 Hard

Write a Matrix2 class with multiplication, determinant and fast exponentiation, and use [[1,1],[1,0]]n to compute Fibonacci numbers.

Question page & discussion
Question 4 Easy

Read n students with three marks each into a vector of Student objects; each object computes its total, percentage and result. Print a report and the topper.

Question page & discussion
Question 5 Medium

Write an Inventory class holding Item objects with add (merging existing items), remove with stock checks, total value, and a list of items low on stock.

Question page & discussion
Question 6 Easy

Write a Point class with distance_to, midpoint and a static centroid function for a vector of points, and print the results.

Question page & discussion
Question 7 Hard

Write a Polynomial class storing coefficients (lowest power first) with evaluation by Horner's method, addition, derivative and printing.

Question page & discussion
Question 8 Hard

Implement a CircularQueue class over a fixed std::array with head/tail indexes that wrap around, supporting enqueue, dequeue, size and full/empty checks.

Question page & discussion
Question 9 Medium

Write a Time class storing seconds since midnight that adds positive or negative durations, wraps around midnight, and prints hh:mm:ss.

Question page & discussion
Question 10 Medium

Write a User class whose constructor assigns a unique, never-reused ID from a static counter, and a Registry that stores users, finds them by ID and removes them.

Question page & discussion
All exercises doneBack to Classes and ObjectsRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links