Archive

Posts Tagged ‘constructor’

An Event Class With Time And Date Objects

May 21st, 2011 Comments off

I need this by sunday 5/22/11 at noon if possible.

1. Create a project which consists of three classes: an Event class, a Time class, and a Date class.
2. The Event class should have data members that are objects of the Time and Date class.

STEP 2: the Event and Time Classes

1. the code for the Event and Time classes should include all necessary function and constructor implementation code.

STEP 3: Design a Date Class

1. Design a Date class that has three data members to represent the year, month, and day.
2. Date-class member functions should be able to

set the date,
return the date,
print the date, and
add a default constructor and a constructor with parameters.
STEP 4: Construct Main Method

1. Construct the main method so that it can test the member functions of each of the classes by creating an Event object and then performing the necessary operations to test all possible behavior.

This is what i have so far.

#include <iostream>
#include <string>

using namespace std;

class Time
{
//this is a simple time class to demonstrate the use of one
//object within another class (composition)

public:
void setTime(int, int);
void getTime(int&, int&);
void printTime() const;
void incrementMin();
void incrementHrs();
Time(int, int); // constructor with parameters
Time(); // the default constructor

private:
int hour;
int minute;
};

class Event
{
publilc:
void setEventData(string eventName, int hour, int minute, int month, int day, int year);
// this is the prototype of the function to set the data for
// the event
void printEventData() const;
Event(string eventName = 1, int day = 1, int year = 1900);
// Constructor

private:
string eventName;
Time eventTime; // the event object is composed of a time object
dateType eventDay //and a date object

};

Categories: Programming Tags: , , , , , ,

The Extended Time Zone Class

March 18th, 2010 Comments off

This is a C++ project. Pretty simple.

I have attached a sample output as something to reference.

STEP 1: Create a New Project

Create a new project which consists of two classes; the base Time class and a derived extTime class.

The base class should have data members that are used to represent the hour and the minute both of type integer. The derived class has one additional data member that represents the time zone. This data member should have a string data type.

STEP 2: Create and define member functions

Create a function for each of the operations listed below:

Base class:

* set the time
* return the time
* print the time
* increment the hour
* increment the minute
* a default constructor and a constructor with parameters.

Derived class: should have (in addition to the classes above) its own

* print which prints the time zone in addition to the time
* constructor

STEP 3: Construct Main Method

Construct the main method so that it can test the member functions of each of the parent and the child class by instantiating objects of these classes and calling the appropriate functions.

let me know of any questions thanks!

Categories: C/C++ Tags: , , , , , ,

The Extended Time Zone Class

November 15th, 2009 Comments off

Create a new project which consists of two classes; the base Time class and a derived extTime class.

The base class should have data members that are used to represent the hour and the minute both of type integer. The derived class has one additional data member that represents the time zone. This data member should have a string data type.

STEP 2: Create and define member functions

Create a function for each of the operations listed below:

Base class:

set the time
return the time
print the time
increment the hour
increment the minute
a default constructor and a constructor with parameters.
Derived class: should have (in addition to the classes above) its own

print which prints the time zone in addition to the time
constructor
STEP 3: Construct Main Method

Construct the main method so that it can test the member functions of each of the parent and the child class by instantiating objects of these classes and calling the appropriate functions.

Categories: C/C++ Tags: , , , , , ,

Homework Help

September 27th, 2009 Comments off

I’m having trouble with my C++ homework assignment that is due at 10pm PST tonight. I’m looking for someone that can create the following program with detailed comments so that I can learn from it as well.

1) Create a new project which consists of three classes; an Event class, the Time class and a Date class. The Event class should have data members that are objects of the Time and Date class.

2) Design the implementation code: Extend the code for the Event and Time classes given in the lecture notes to include all necessary function and constructor implementation code. ***posted at the bottom***
Also design a Date class which has three data members to represent the year, month and the day. Here are the cod for Event and Time from class.

Date class member functions should be able to:

set the date
return the date
print the date
add a default constructor and a constructor with parameters.

3) Construct the main method so that it can test the member functions of each of the classes by creating an Event object and then performing the necessary operations to test all possible behavior

Categories: C/C++ Tags: , , , , , ,

Tutoring Assistance.

September 20th, 2009 Comments off

I’m taking an online class and have to write a program with the following criteria. I have not been able to get the program to work, I’m new to programming and looking for someone to deliver this ASAP, it’s due tonight at midnight. Also, the solution must have details comments explaining what has been done, so hopefully I can learn from it.

1) Create a new project which consists of two classes; the base Time class and a derived extTime class.

The base class should have data members that are used to represent the hour and the minute both of type integer. The derived class has one additional data member that represents the time zone. This data member should have a string data type.

2) Create a function for each of the operations listed below:

Base class:

* set the time
* return the time
* print the time
* increment the hour
* increment the minute
* a default constructor and a constructor with parameters.

Derived class: should have (in addition to the classes above) its own

* print which prints the time zone in addition to the time
* constructor

3) Construct the main method so that it can test the member functions of each of the parent and the child class by instantiating objects of these classes and calling the appropriate functions.

Categories: C/C++ Tags: , , , , , ,

Java Inventory Program Part 1

March 16th, 2009 No comments

When i try to compile my java program it says it has two errors and it wont compile with the two errors heres the code

import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class Inventory {

public static void main(String args []) {
//create new object
DVD mydvd = new DVD();
//create and intialize arrayof products
DVD[] prodArray = new DVD[6];
prodArray[0] = new DVD(“Action”,15,59,22.00);
prodArray[1] = new DVD(“Westerns”,26,68,16.00);
prodArray[2] = new DVD(“Drama”,22, 71, 15.00);
prodArray[3] = new DVD(“Comedy”,33, 50, 19.00);
prodArray[4] = new DVD(“Sci-Fi”,66, 42, 14.00);
prodArray[5] = new DVD(“Horror”,27, 53, 24.00);

//For each array element, output value
for (int counter = 0; counter &lt; prodArray.length; counter++ )

{
System.out.println(“Item Number: ” + prodArray[counter].getitemNum());
System.out.println(“Product Name: ” + prodArray[counter].getName());
System.out.println(“Quantity: ” + prodArray[counter].getunits());
System.out.println(“Unit Price: ” + prodArray[counter].getprice());
System.out.println(“Total Value: ” + prodArray[counter].getvalue());
System.out.println(); //blank line to seperate products

}//end array output

} //end main

} // end class Inventory

// Class DVD holds DVD information

import java.util.Locale;
import java.text.NumberFormat;

class DVD
{
public String name;
public Integer itemNum;
public Integer units;
public Double price;
//default constructor
public DVD()
{
name = “”;
itemNum = 0;
units = 0;
price = 0.00;
}//end default constructor
//Parameterized Constructor
public DVD(String name, Integer itemNum, Integer units, Double price)
{
this.name = name;
this.itemNum = itemNum;
this.units = units;
this.price = price;
}//end constructor

//Set product information
public void setName(String name) {
this.name = name;
}
public String getName()
{
return name;

}

public void setitemNum ( int itemNum )
{
this.itemNum = itemNum;
}

public Integer getitemNum()
{
return itemNum;
}
public void setunits ( int units )
{
this.units = units;
}
public Integer getunits()
{
return units;
}
public void setprice ( Double price )
{
this.price = price;
}
public Double getprice()
{
return price;
}
public Double getvalue()
{
return (units * price);
}

// the compareTo method is used to implement the Comparable interface. This enables us to sort a list of Products using Arrays.sort()
// this method returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item
public int compareTo (Object o)
{
DVD d = (DVD) o;
return name.compareTo(getName());
}

// returns a string representation of the DVD
public String toString()
{
return “DVD Name : ” + getName() + “n”
+ “DVD Number : ” + getitemNum() + “n”
+ “DVD Price : ” + NumberFormat.getCurrencyInstance(Locale.US).format(getprice()) + “n”
+ “Number in Stock : ” + getunits() + “n”
+ “Value of inventory : ” + NumberFormat.getCurrencyInstance(Locale.US).format(getvalue());
}

}//end Class DVD

the comment my teacher left was:
Hi Blanche. Your program did not compile or run. I was not able to test your
program. However, I did try to award partial credit by reading the code. The
assignment required you to create a separate class to store some product. The
inventory class should use the set methods to store the information into the
product class and use the get methods to retrieve the information from the
product class. It looks like your program is mostly correct. Your program did
not compile because your file name does not match the class name.

Bear