Member Avatar for iamthwee

Hi everione,

my next assinement is 2 do with classes. I dun no what they are tho and why u will use them? Can any1 explain them to me I would B greatfull. God bless. :o

Why should we help someone who doesn't even take the time to write out his sentences?
If you're that lazy you don't deserve help.

A c++ class is just a way to organize data and associated methods. Whole books have been written on the subject so there isn't enough time or bandwidth to explain them here. I'm sure if you open your text book it will explain them.

Hi everione,

my next assinement is 2 do with classes. I dun no what they are tho and why u will use them? Can any1 explain them to me I would B greatfull.

You're taking a class and you want us to do work for you because you didn't feel like paying attention to your instructor?

Classes are a way of defining datatypes. GL on ur assininement.

HTHHAND. N!

Member Avatar for iamthwee

tank u very much for your help.

maybe i wasn't clear. so i provide u with my assignment to give you help. Basically i am so confused. I barely understand a function and now i have to do a class. Why do I need these please help!

Write a program that outputs a telephone bill, given information on telephone calls made by the user.

A telephone call is described by starting and stopping times, where the times are given in the form hh:mm/dd/mm/yyyy; hh is the hour, mm is the minute, dd is the day, mm is the month and yyyy is the year, all of which are integers.

The following table describes the cost of a phone call per minute.

time cost per minute
00:00 - 07:59 0.10
08:00 - 16:59 0.15
17:00 - 23:59 0.12


A suggested way to attack this problem
The following attack on this problem is not the most efficient method, but I think it is the easiest way to break it down into workable parts.
The idea is this: first write a program that is given a starting time and a stopping time, and then counts up from the starting time to the ending time, minute by minute. After this works, add code that adds the appropriate charge per minute as you count.


The counter class


The time_and_date class
Now create a class that has as data
a counter for the hours
a counter for the minutes
a counter for the days
a counter for the months
a counter for the years

<< moderator edit: fixed tags >>

Am i using this proberly? :cry:

This forum? No, you're not. If you look at the top, there's a thread saying "We only give homework help to those who have shown effort."

Unfortunately, you haven't.
If you want an easy tutorial, check this site:
http://cplus.about.com/cs/ctutorial1/index_2.htm

It's probably not the best, but it's simple and provides questions with solutions.

I reccomend you go through it step-by-step up to lesson 10 on the first page, then you can read 14, 17, and 18 to get a general idea of functions and classes. There are any number of tutorials for C++ online, just google C++ Tutorial.

Then, when you're at this board, search for your question's keywords first, and you'll probably find that there are other people who have gotten answers already...

The important thing to this board is to ask specific questions when you have specific problems. The a class is such a general and basic topic in C++ that you're not going to get much help here, I'm afraid...

Good luck.

EDIT: One more thing: Your assignment comes with suggestions on how to approach the problem.
Before you start coding, you should define your approach, and then, even if you don't have the code itself, you can ask us to help you write sections of the code... but you've got to give it a try yourself, first.

in object oriented methodology, classes are nothing but blue prints out of which objects are made of. you can think of classes as structures in c. except they are different in a few aspects.a class specifies the state and behaviour of the objects that can be created from that class.a class can have sub-class.(this topic is related to inheritance).but since u are a beginner.you just need to know the definition of a class.which i have provided.

Member Avatar for iamthwee

Hi guys i have got this so far. I need help on how to make the class. I only have a function so far tank u very much. Pleaz can u check it 4 me. :D

// A program which calculates the cost of a phone call
// Notes
//------
// The phone call must be made on the same day to
// simplify your model. Those who wish to earn
// extra credit for this assignment can consider
// using the month and year if they wish
//
// Implement three CLASSES,count mins,count hours and
// call charge. You can use header files if you wish 
// the choice is yours.

#include <iostream>

using namespace std;

/*Function declarations*/
int count_hours(); //returns no. hours
int count_mins();  //return no. minutes
int call_charge(); //call charge per min


int main()
{
    char start_call[100];
    char end_call[100];
    char cost[5];
    
    cout<<"Please enter the start time using this format,"<<endl;
    cout<<"10:30/4/8/1997:";//use 24 hour time
    
    cin>>start_call;
    
    cout<<"Please enter the end time using this format,"<<endl;
    cout<<"16:30/4/8/1997:"; //use 24 hour time
    
    cin>>end_call;
    
    cout<<"Please enter the cost per minute $:";
    cin>>cost;
    //cout<<cost;
    
    //Now read in the first five chars
    //Convert the numbers to integers using the 'atoi' function
    char temp[2];
    char temps[2];
    for (int a=0; a<2; a++)//arrays start from 0.
    { 
        temp[a]=start_call[a];
    }
    temp[2]='\0';  
      int b;
      b=atoi(temp);
      cout<<b<<endl;
    
    for (int k=0; k<2; k++)//arrays start from 0.
    { 
        temps[k]=end_call[k];
    }  
    temps[2]='\0';
      int c;
      c=atoi(temps);
      cout<<c<<endl;
        
        
    cin.get();
    cin.get();
}

You have used the functional programming to come up with this program.

In order to make this an object oriented program, you have to put this data into a class and use an object of that class form the main progam.

To give a very rough idea, all the data in main can be used as the data members of the class.
The processing done in the main function could be broken into several logical parts and can become the methods of the class.

Then use an object of this class in the main program and call the methods of the class on top of the object from within the main program.

____________________________________________________
Programming ( Assignment / Project ) Help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.