a) Write c++ expression for the following algebraic expression y = 2a + b/a - b,
ID: 2246993 • Letter: A
Question
a) Write c++ expression for the following algebraic expression y = 2a + b/a - b, assume a and are declared and defined. b) Declared a floating point variable: x as below: double x: Write a C++ statement to read a value for x (an input statement) with a proper prompt. c) Write a selection statement to do the following: if hour less than or equal to 40, salary hour x wageRate, otherwise, salary = 40 x wageRate + (hours - 40) x overTime Assume that all the variables are already declared and their values are initialized. d) Declare a named constant GREET whose value is "Merry X-Mas" e) Convert the following expression suitably in C++ using library function. Balance = Principal * (1+RATE/T)^T Assume Principal, Rate and T are all known. T is the number of terms the interest is compounded.Explanation / Answer
1- #include<iostream>
using namespace std;
int main()
{
int a=10,b=5;
float y=((2*a)+b) / (a-b);
cout<<y;
}
2-
#include<iostream>
using namespace std;
int main()
{
double x;
cout<<"Enter value of x";
cin>>x;
}
3-
#include<iostream>
using namespace std;
int main()
{
float salary,hour=5,wagerate=100,overtime;
if(hour<=40)
salary=hour*wagerate
else
salary=40*wagerate + (hours-40)*overtime;
}
4-
//file.h
class A{
private:
static const std::string GREET;
}
#include "file.h"
const std:: string A::GREET="Merry X-Mas";
5-
#include <stdio.h>
#include <math.h>
int main ()
{
int balance,principal=3000,rate=2,t=5;
balance=principal*(pow((1+(rate/t)),t));
cout<<balance;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.