#include <iostream>
#include <iomanip>

using namespace std;
class Derivate

{
   public:   
   showDerivate();
   void showFunc();

   };

   int main()

   {   int nr;
       Derivate drv;
     drv.showFunc();
     drv.showDerivate();
     std::cin.get();
     return 0;
   }

   void Derivate::showFunc()
   { 
       cout<<"Nr"<<setw(20)<<"Function"<<endl;
       cout<<"1"<<setw(20)<<"x"<<endl;
       cout<<"2"<<setw(20)<<"cx"<<endl;
       cout<<"3"<<setw(20)<<"xpowc"<<endl;
       cout<<"4"<<setw(20)<<"1/x"<<endl;
       cout<<"5"<<setw(21)<<"1/xpowc"<<endl;
       cout<<"6"<<setw(20)<<"sqrt x"<<endl;
       cout<<"7"<<setw(21)<<"epowx"<<endl;
       cout<<"8"<<setw(20)<<"lnx"<<endl;
       cout<<"9"<<setw(20)<<"sinx"<<endl;
       cout<<"10"<<setw(20)<<"cosx"<<endl;

   }

   int Derivate::showDerivate()
   {cout<<"give the respective number ofe the function you want to derivate"<<endl;
     cin>>nr;
     if (nr !=-1){
      cout<<"function"<<setw(21)<<"derivate"<<endl;
        switch (nr)
      {  case 1: cout<<"x"<<setw(21)<<"1"<<endl;
             break;
      case 2: cout<<"cx"<<setw(21)<<"c"<<endl;
          break;
      case 3: cout<<"xpowc"<<setw(21)<<"c*xpow c-1"<<endl;
          break;
      case 4: cout<<"1/x"<<setw(21)<<"-1/xpow2"<<endl;
          break;
      case 5: cout<<"1/xpowc"<<setw(21)<<"-c/xpow(c+1)"<<endl;
          break;
      case 6: cout<<"sqrt x"<<setw(21)<<"1/2sqrtx"<<endl;
          break;
      case 7: cout<<"epowx"<<setw(21)<<"epowx"<<endl;
          break;
      case 8: cout<<"lnx"<<setw(21)<<"1/x"<<endl;
          break;
      case 9: cout<<"sinx"<<setw(21)<<"cosx"<<endl;
          break;
      case 10: cout<<"cosx"<<setw(21)<<"-sinx"<<endl;
          break;}
     }
     else
     {return int showDerivate();}
   }

what kind of return value should i use with showDerivate?and i'm not sure about the recursion too, please help me , thanks !!!

I'm guessing from your code that you might want to keep executing the lines that tell the user to chose a number and then process the choice to output the correct line from the switch statement. You could do this by recursion (although you have it a bit muddled here, so it won't work quite as you expect), but it might be easier to use a do{ ... }while() loop. So, something like:

int nr;
do{
   std::cout << "Enter choice" << endl;
   std::cin >> nr;
   printChoice(nr);
}while(nr != -1);

This will go through the loop at least once and then keep going through it until -1 is entered by the user. I've made a function printChoice() that I'm imagining has all the details of the switch() statements in it.

Also, use code tags!

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.