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 program in c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
Write a program in C# for a Cricket match using Jagged Arrays. The name of the...
Write a program in C# for a Cricket match using Jagged Arrays. The name of the project will be on your name. It has the following modules: Create two functions in class Cricket_Match for random numbers generation. The first function generates 1-6 numbers which is known as balls played by each player. The second function generates a 0-6 number which is known as the score produced against each ball by an individual player. In the main show the individual player...
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]
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 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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT