Question

In: Computer Science

1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters,...

1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters, dimes, nickels, and pennies in a given amount of money. The input should be a floating-point value representing a decimal value. Example: 63.87 à 63 [dollars and 87 cents] should output 63 dollars, 3 quarters, 1 dime, 0 nickels, and 2 pennies.

2. In trigonometry the cosine function can be calculated using cos(x) = 1 – x 2 /2! + x 4 /4!- x 6 /6! + x8 /8!- … Write a C++ program that uses a function to calculate the cos of a positive value (radians) by summing the 1st 15 terms of this series. You will need to write a separate function to calculate a factorial. Write another function that calculates the relative error between using 15 terms and 5 terms. The relative error can be calculated as |cosine(x, 15) – cosine(x, 5)|/cosine(x, 15).

Solutions

Expert Solution

question 2 solution

// CPP program to find the
// sum of cos(x) series
#include <bits/stdc++.h>
using namespace std;

const double PI = 3.142;

double fact(double c, int i)
{
c = c * (2 * i - 1) * (2 * i);
return c;
}

double cosXSertiesSum(double x,
                   int n)
{

   double res = 1;
   double sign = 1, c = 1,
                   pow = 1;
  
   for (int i = 1; i < n; i++)
   {
       sign = sign * -1;
       c = fact(c,i);
       pow = pow * x * x;
       res = res + sign *
           pow / c;
   }

   return res;
}

double error(double x)
{
double a = cosXSertiesSum(x,15) - cosXSertiesSum(x,5);
if(a<0)
{
a = a - 2*a;
}
return a/cosXSertiesSum(x,15);
}

// Driver Code
int main()
{
   double x;
   cout<<"Enter the value in radians"<<endl;
   cin>>x;
   int n = 15;
   cout << cosXSertiesSum(x, n)<<endl;
   cout<<error(x);
}

question 1 solution

#include<iostream>
using namespace std;

struct Money{
int dollars;
int cents;
  
};

int print(Money);
Money cent(Money);

int main()
{
struct Money m;
m.dollars = 63;
m.cents = 87;
print(m);
}

Money cent(Money m)
{
cout<<"Quaters "<<m.cents/25<<endl;
m.cents = m.cents-(25*(m.cents/25));
cout<<"Dime "<<m.cents/10<<endl;
m.cents = m.cents-(10*(m.cents/10));
cout<<"Nickels "<<m.cents/5<<endl;
m.cents = m.cents-(5*(m.cents/5));
cout<<"Pennies "<<m.cents/1;
}

int print(Money m){
cout<<"Dollars are "<<m.dollars<<endl;
cent(m);
}


Related Solutions

A local instructor wants you to write a c++ program using arrays to calculate the average...
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions with arguments. Create programs with small functions where main goes to a series of functions where the real work takes place. Don’t use global variables and don’t use break within a loop (unless working with a switch statement). Functions can’t have more than 30 statements of code, not including comments, blank lines, or variable definitions. Don’t use a return in the middle of the...
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a c program to calculate the factorial of a number using recursion    [8] Question five...
Write a c program to calculate the factorial of a number using recursion    [8] Question five Write a stack algorithm to POP an item                                                         [6] What does FRONT and REAR signify in a queue?                                                                 [6] Write an algorithm for a dequeue operation                                                                       [8]
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation , all numbers must be between 0 and 100) 2) find the largest number 3) Find the Smallest Number 4) Find the Sum of all numbers in the Array Display: as per the user's section (menu using switch or if else ) Largest Number Smallest Number Sum of all numbers the original Array DO NOT USE METHODS OR FUNCTIONS Submit: Source code (C++) output...
C coding • Implement, using structures and functions as appropriate, a program which requires you to...
C coding • Implement, using structures and functions as appropriate, a program which requires you to enter a number of points in 3 dimensions. The points will have a name (one alphanumeric character) and three coordinates x, y, and z. Find and implement a suitable way to stop the input loop. The program, through an appropriate distance function, should identify the two points which are the furthest apart. Another function should calculate the centre of gravity of the point cloud...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
In C# A Tic Tac Toe program that uses functions and arrays. The program should start...
In C# A Tic Tac Toe program that uses functions and arrays. The program should start by asking the player one for their name and then player two for their name. Then should print the board and ask the user what column and then what row they would like to put their x (or o, depending on the player) . Use the clear function to make it look as though the board is never repeating.. Thanks!
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT