[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 11681 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 90 days
Recommended Popular Threads Controvertial Threads
TPS To F-1 COS
Nepal TPS has been Extended !!!
Got my F1 reinstatement approved within 3 months(was out of F1 for almost 2 years)
Nepal TPS decision
ICE kidnapping people off the streets over op eds
Has anyone here successfully reinstated to F-1 status after a year-long gap following a drop from F-1?
TPS to F1 Status.
US citizen Petitioning my wife who was out of status when she was in H1B. What to do ?
TPS of Nepal to be automatically extended for 6 months based on South Sudan decision
Genuine Question.... Why so many folks still in TPS after 10 years. Is the statistics wrong?
#MAGA#FAFO is delicious
Please ask KRISTI NOEM in her facebook and other social media to renew TPS
Any input on remote jobs(IT related or Sales or Marketing)?
Don’t Just Read—Join the Conversation
Supreme Court allows Trump to end TPS for Venezuelans
Nepal Likely to Get 60-Day TPS Notice
TPS Sakiyo Tara Case is in Court.
नेपाल मा B. sc गरियो यहाँ फेरी ७० -८० क्रेडिट पढ्नु पर्ने भो
EAD HELP NEEDED URGENTLY!
Need Help of IT consultancies
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