How to calculate in C++?? PLS HELP ME?

How to compute financial ratio in C++ with using header file?

Calculate in c++ program with 3 different file. - 2 file (cpp file) - 1 file (header file)

Information:

formula:-
*1.*Current ratio = (current asset / current liabilities)
*2.*Gross margin = (Revenue – Cost of goods sold) / Revenue
*3.*Operating margin= (Operating Income / Revenue)
*4.*Profit margin = (Net Profit / Revenue)
*5.*ROE= (Net Income/Shareholder's Equity)

I want put 5 formula to run the program. How to put 5 formula in the program but run one formula.

EXAMPLE: In the coding, write all financial ratio. When we compile, just asking 1 formula value only. We need to fixed, which formula to run. Just adjust the coding only. HOW?? pls help.

Please correct me If I'm wrong. I just start study C++ program.
You need to show what you've tried so far before you can receive help.
Hello Austin J,

1.Main:cpp

#include <current.h>

using namespace std ;

double current(double asset, double liability)
{
return asset / liability;
}

2.cpp file

double current(double asset, double liability)

{
return asset / liability;
}

3.header file

#ifndef CURRENT_H_INCLUDED
#define CURRENT_H_INCLUDED

using namespace std;

double current(double asset, double liability);

#endif // CURRENT_H_INCLUDED


I did something but Im not sure it is correct or not. I did 1 formula. Just tried only. Can you help me?
Last edited on
this program won't compile as an executable because it's lacking a main function.

let me show you a sample function and the structure of the program:

functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef FUNCTIONS_H
#define FUNCTIONS_H

class finance_state
{
    double current_asset , current_liabilities;
public:
    finance_state(double ca , double cl);
    ~finance_state();

    double    CurrentRatio();
};
#endif 


functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "functions.h"

    finance_state  ::  finance_state(double ca , double cl) :
                                    current_asset(ca) ,
                                    current_liabilities(cl) 
{
}

    finance_state  ::  ~finance_state()
{
}

double    finance_state  ::  CurrentRatio()
{
    double temp = this->current_asset / this->current_liabilities;
    return temp;
}


EntryPoint.cpp
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "functions.h"

int    main   ()
{
    finance_state MyState( 500.0 , 300.0 );
    std::cout<< "my current ration is :\t"<< MyState.CurrentRatio()<<std::endl;
    return 0;
}


you can extend on this base to implement the remaining functionality.

PS : this code is written on the fly, i didn't try it yet.
if you find any errors, please report them to me.
Hello Rechard3,

Thank you. The program is run successful.

Above shows only one formula. How to add 4 formula. Just now, I try to do but it show error in the program. Can you help me? Which one has to adjust? I has put 5 formula in this program then I adjust the code to run but it shows the error. I try to adjust few coding many time but can not run. :(

Hello Austin J,

Did you have a suggest?
i suggest you refer to the book you're reading and see what it says about classes.
if you don't have a book, you can check the documentation on this site:

part 1:
http://www.cplusplus.com/doc/tutorial/classes/

part 2:
http://www.cplusplus.com/doc/tutorial/classes2/

after you read this, you'll have no problem defining the remaining functionality.
OK... I will read and understand the resources that you provided. I will try my level best to do myself. If I can not run the program, I will inform you.

I will post the code also and you try to help, which line is wrong then you help me. Give me some time to do.

Thank you for supporting me and thanks for your resources. Will contact with you soon. :)
Rechard pretty much covered it. Also you may want to look at this article -
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.