Namaste!!! 1. NumDays class Design a class called NumDays. The class’s purpose is to store a value that represents a number of work hours and convert it to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days. The class will have a constructor that accepts a number of hours, as well as member functions for storing and retrieving the hours and days. The class will also have the following overloaded operators: + Addition operator. When two NumDays objects are added together, the overloaded + operator will return the sum of the two objects’s hours member. - Subtraction operator. When one NumDAys object is subtracted from another, the overloaded - operator will return the difference of the two object’s hours member. ++ Prefix and postfix increment operators. These operators will increment the number of hours stored in the object. When incremented, the number of days will be automatically recalculated. -- Prefix and postfix decrement operators. Theses operators will decrement the numbers of hours stored in the object. When decremented, the number of days will be automatically recalculated. Last edited: 12-Apr-11 03:56 PM
nepali8 · Apr 12, 2011 2:12 PM · 14,627 views
Try this one buddy class numDay { int hour;int day; void hour{ if(hour>=8) { day++; cout<<day; }} void day { if { hour=hour-8; cout<<hour; hour++; }} } main { numday a,numday b;numday c; c.hour==a.hour-b,hour; c.day==a.day-b.day; cout<<c.hour(); cout<<c.day(); end }
rahul80 · Apr 12, 2011 4:20 PM
Namaskarr!! class NumDays { int hours; 1) create constructor with numHours as parameter and set it to hours 2) create getter and setter for hours 3) make method getDays() something like below public float getDays() {return hours/8;} 4) overload operators + something like below int::operator+(NumDays &rhs) { return this.hour + rhs.hour } overload other operators similarly Last edited: 12-Apr-11 04:33 PM Last edited: 12-Apr-11 04:34 PM
prankster · Apr 12, 2011 4:32 PM
this is in java, // a bit left...complete by urself package demo.test; public class NumDays { private int days; public NumDays(int hours){ if(hours <=8){ days=(hours-(hours-1)); days = hours; } } public int getWork_hours() { return days; } } //test class package demo.test; public class TestNumDays { public static void main(String[]args){ NumDays nd = new NumDays(8); System.out.println("No of Days:\t"+nd.getWork_hours()); } }
Ayus · Apr 12, 2011 4:46 PM
#ifndef NUMDAYS_H #define NUMDAYS_H #include <iostream> class NumDays { private: int hours; float day; public: NumDays() { hours=0; day=hours/8.0; } NumDays(int a) { hours=a; day=hours/8.0; } void setHours(int); int getHour()const{return hours;} float getDay()const{return day;} int operator+(NumDays &); int operator-(NumDays &); int operator++(int); int operator++(); int operator--(int); int operator--(); }; #endif #include <iostream> #include <cstdlib> #include "Numdays.h" using namespace std; void NumDays::setHours(int a) { hours=a; } int NumDays::operator +(NumDays & right) { int totalHours; totalHours=hours+right.hours; return totalHours; } int NumDays::operator -(NumDays & right) { int total_Hours; total_Hours=hours-right.hours; return total_Hours; } int NumDays::operator ++(int) { int Self=hours; hours++; day=hours/8.0; return Self; } int NumDays::operator ++() { hours++; day=hours/8.0; return hours; } int NumDays::operator --(int) { int Self=hours; hours--; day=hours/8.0; return Self; } int NumDays::operator --() { hours--; day=hours/8.0; return hours; } i think i am doing right up to here. This is what so far i got. i need a int main...program to call this function. thanks for help.
nepali8 · Apr 19, 2011 12:41 PM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion