You plan to revise on all learnt topics and explore the sequence of repetitive printing using while loop. For this, you decide to write a modular C++ program to neatly print a table of sine, cosine and tangent for a range (i.e. lower and upper bounds) of radian values based on userentered angle range, on screen as well as in an output file. The increment between successive angle values is based user-entered angle value. You plan to implement at least THREE user-defined functions and your program must first check to ensure that the lower bound angle value is smaller than the upper bound angle value and that the incremental angle value is smaller than the absolute value of lower bound angle. If not, an error message is to be displayed and the program ends.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The topics are:

>>How to declare constants.

>>How to Implement Arithmetic Operations.

>>How to Implement Decision (Part 1: if - elseif - else).

please this is a C++ program.

You plan to revise on all learnt topics and explore the sequence of repetitive
printing using while loop. For this, you decide to write a modular C++ program
to neatly print a table of sine, cosine and tangent for a range (i.e. lower and upper
bounds) of radian values based on user-entered angle range, on screen as well
as in an output file. The increment between successive angle values is based
user-entered angle value. You plan to implement at least THREE user-defined
functions and your program must first check to ensure that the lower bound
angle value is smaller than the upper bound angle value and that the incremental
angle value is smaller than the absolute value of lower bound angle. If not, an
error message is to be displayed and the program ends.
A sample output is as below:
Lower bound angle value: 45
Upper bound angle value: 60
Incremental angle value: 5
Angle
sine
cosine
tangent
45
0.707107
0.707107
50
0.766044
0.642788
1.19175
55
0.819152
0.573576
1.42815
60
0.866025
0.5
1.73205
Transcribed Image Text:You plan to revise on all learnt topics and explore the sequence of repetitive printing using while loop. For this, you decide to write a modular C++ program to neatly print a table of sine, cosine and tangent for a range (i.e. lower and upper bounds) of radian values based on user-entered angle range, on screen as well as in an output file. The increment between successive angle values is based user-entered angle value. You plan to implement at least THREE user-defined functions and your program must first check to ensure that the lower bound angle value is smaller than the upper bound angle value and that the incremental angle value is smaller than the absolute value of lower bound angle. If not, an error message is to be displayed and the program ends. A sample output is as below: Lower bound angle value: 45 Upper bound angle value: 60 Incremental angle value: 5 Angle sine cosine tangent 45 0.707107 0.707107 50 0.766044 0.642788 1.19175 55 0.819152 0.573576 1.42815 60 0.866025 0.5 1.73205
Expert Solution
Step 1 Code

main.cpp

#include <iostream>
#include <cstdlib>
#include <math.h>
#include <fstream>
#include <iomanip>
using namespace std;

int validate(float lowerValue, float upperValue,float incValue)
{
    if(lowerValue>=upperValue)
        return 0;
    else if(abs(lowerValue)<=incValue)
        return 0;
    return 1;
}
void print(float lowerValue, float upperValue,float incValue)
{
    float angle;
    cout<<"\n --------------------------------------------------------------------------";
    cout<<"\n  Angle \t sine \t\t cosine \t tangent";
    cout<<"\n --------------------------------------------------------------------------"<<endl;
    for(float i = lowerValue;lowerValue <= upperValue;lowerValue+=incValue)
    {
        angle = lowerValue * 3.14159/180;
        std::cout<<"   "<<lowerValue<<"\t\t"<<sin(angle)<<"\t"<<cos(angle)<<"\t"<<tan(angle)<<endl;
    }
}
void printToFile(float lowerValue, float upperValue,float incValue)
{
    ofstream outputFile;
    outputFile.open("output.txt");
    float angle;
    outputFile<<"\n --------------------------------------------------------------------------";
    outputFile<<"\n  Angle \t sine \t\t cosine \t tangent";
    outputFile<<"\n --------------------------------------------------------------------------"<<endl;
    for(float i = lowerValue;lowerValue <= upperValue;lowerValue+=incValue)
    {
        angle = lowerValue * 3.14159/180;
        outputFile<<"   "<<lowerValue<<"\t\t"<<sin(angle)<<"\t"<<cos(angle)<<"\t"<<tan(angle)<<endl;
    }
    outputFile.close();
}
int main()
{
    float lowerValue, upperValue, incValue;
    
    cout<<"\n Lower bound angle value: ";
    cin>>lowerValue;
    cout<<"\n Upper bound angle value: ";
    cin>>upperValue;
    cout<<"\n Incremental angle value: ";
    cin>>incValue;
    
    if(validate(lowerValue, upperValue, incValue))
    {
        print(lowerValue, upperValue, incValue);
        printToFile(lowerValue, upperValue, incValue);
    }
    else
    {
        cout<<"\n Please enter valid input.";
    }
    return 0;
}

 

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY