C++ OO Format Implement a simple user interface, from which you ask the user of
ID: 3795764 • Letter: C
Question
C++ OO Format
Implement a simple user interface, from which you ask the user of your program to input a positive integer, and then you get the input from the interface Let's say the input integer is N Implement the following functions. f(n) = log n g(n) = n log n h(n) = n p(n) = n^2 q(n) = n^3 w(n) = 2^n d(n) = n! The log is natural logarithm. You can call/use all the built-in/library functions in C++ to implement the above functions. Run each of the above functions on all the integers from 1 up to N, and time the execution in seconds. The pseudo-code is something like start your timer: for (n = 1; nExplanation / Answer
solution;
#include<stdio.h>
#include<ctime>
#include<cstdlib>
#include<iostream>
#include<math.h>
#include<fstream>
using namespace std;
int main()
{
clock_t startingTime = clock();
ofstream myfile("D:\example.txt");
int n;
cout<<"please enter a int value to calculate the below funcitons"<<endl;
if (myfile.is_open())
{
cin>>n;
double res;
for(int i=1;i<n;i++)
{
cout<<" *****************************************************"<<endl;
cout<<"******************************************************"<<endl;
res=log(i);
cout<<"the log value of "<<i <<" is "<<res<<endl;
cout<<" "<<endl;
myfile <<"the log value of "<<n<<" is "<<res<<endl ;
res=i*log(i);
cout<<"the nlogn value of "<<i <<" is "<<res<<endl;
cout<<" "<<endl;
myfile <<"the nlogn value of "<<n<<" is "<<res<<endl ;
res=i;
cout<<"the h(n)=n value of "<<i <<" is "<<res<<endl;
cout<<" "<<endl;
myfile <<"the h(n) value of "<<i<<" is "<<res<<endl ;
res=i*i;
cout<<"the n*n value of "<<i <<" is "<<res<<endl;
cout<<" "<<endl;
myfile <<"the p(n) value of "<<n<<" is "<<res<<endl ;
res=i*i*i;
cout<<"the n*n*n value of "<<i <<" is "<<res<<endl;
cout<<" "<<endl;
myfile <<"the q(n) value of "<<i<<" is "<<res<<endl ;
res=exp(i);
cout<<"the exp(n) value of "<<i <<" is "<<res<<endl;
cout<<" "<<endl;
myfile <<"the exp(n) value of "<<i<<" is "<<res<<endl ;
int fact=1;
for(int j=i; j>0; j--)
{
fact=fact*j;
}
cout<<"Factorial of "<<i<<" is "<<fact;
cout<<" "<<endl;
myfile <<"the exp(n) value of "<<i<<" is "<<fact<<endl ;
}
myfile.close();
}
else cout << "Unable to open file";
clock_t endingTime = clock();
clock_t noofclocksTicks = endingTime - startingTime;
double noofseconds = noofclocksTicks / (double) CLOCKS_PER_SEC;
cout<<"the time in seconds "<<noofseconds<<endl;
return 0;
}
//i give the result in console and text file also.if you refer text file also same output will appear
output
please enter a int value to calculate the below funcitons
6
*****************************************************
******************************************************
the log value of 1 is 0
the nlogn value of 1 is 0
the h(n)=n value of 1 is 1
the n*n value of 1 is 1
the n*n*n value of 1 is 1
the exp(n) value of 1 is 2.71828
Factorial of 1 is 1
*****************************************************
******************************************************
the log value of 2 is 0.693147
the nlogn value of 2 is 1.38629
the h(n)=n value of 2 is 2
the n*n value of 2 is 4
the n*n*n value of 2 is 8
the exp(n) value of 2 is 7.38906
Factorial of 2 is 2
*****************************************************
******************************************************
the log value of 3 is 1.09861
the nlogn value of 3 is 3.29584
the h(n)=n value of 3 is 3
the n*n value of 3 is 9
the n*n*n value of 3 is 27
the exp(n) value of 3 is 20.0855
Factorial of 3 is 6
*****************************************************
******************************************************
the log value of 4 is 1.38629
the nlogn value of 4 is 5.54518
the h(n)=n value of 4 is 4
the n*n value of 4 is 16
the n*n*n value of 4 is 64
the exp(n) value of 4 is 54.5982
Factorial of 4 is 24
*****************************************************
******************************************************
the log value of 5 is 1.60944
the nlogn value of 5 is 8.04719
the h(n)=n value of 5 is 5
the n*n value of 5 is 25
the n*n*n value of 5 is 125
the exp(n) value of 5 is 148.413
Factorial of 5 is 120
the time in seconds 3.37
--------------------------------
Process exited after 3.394 seconds with return value 0
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.