[Show all top banners]

nepali8
Replies to this thread:

More by nepali8
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 C++ Desperately need help!!!
[VIEWED 9968 TIMES]
SAVE! for ease of future access.
Posted on 04-12-11 2:12 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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

 
Posted on 04-12-11 4:20 PM     [Snapshot: 74]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


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

}
 
Posted on 04-12-11 4:32 PM     [Snapshot: 76]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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

 
Posted on 04-12-11 4:46 PM     [Snapshot: 76]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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());
  }
}

 
Posted on 04-19-11 12:41 PM     [Snapshot: 288]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 



 #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.
 

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 200 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration
What are your first memories of when Nepal Television Began?
निगुरो थाहा छ ??
ChatSansar.com Naya Nepal Chat
TPS Re-registration case still pending ..
Basnet or Basnyat ??
Sajha has turned into MAGATs nest
NRN card pros and cons?
Do nepalese really need TPS?
कता जादै छ नेपाली समाज ??
Will MAGA really start shooting people?
Democrats are so sure Trump will win
मन भित्र को पत्रै पत्र!
Top 10 Anti-vaxxers Who Got Owned by COVID
I regret not marrying a girl at least for green card. do you think TPS will remain for a long time?
TPS Work Permit/How long your took?
emergency donation needed
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
Breathe in. Breathe out.
3 most corrupt politicians in the world
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters