// part h
std::cout << "The square of " << positiveDouble << " is " << square << std::endl;
std::cout << "The square root of " << positiveDouble << " is " << squareRoot << std::endl;
std::cout << "The natural log of " << positiveDouble << " is " << natLog << std::endl;
std::cout << "The log to the base 10 of " << positiveDouble << " is " << base10Log << std::endl;
std::cout << "The sine of " << angleInDegrees << " is " << sine << std::endl;
std::cout << "The cosine of " << angleInDegrees << " is " << cosine << std::endl;
std::cout << "The tangent of " << angleInDegrees << " is " << tangent << std::endl;
return 0;
}
Q3
// Q3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int main()
{
int numGallons = 0;
std::cout << "Enter the number of gallons of gas in a tank" << std::endl;
std::cin >> numGallons;
double numMiles = 0;
std::cout << "Enter the number of miles on a tank" << std::endl;
std::cin >> numMiles;
std::cout << "The car can drive " << numMiles / (double)numGallons << " miles per gallon of gas" << std::endl;
return 0;
}
Q4
// Q4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int main()
{
int numCookies = 0;
std::cout << "How many cookies did you eat?" << std::endl;
std::cin >> numCookies;
int numCookiesPerBag = 30;
int numServingsPerBag = 10;
int numCaloriesPerServing = 300;
//display charges
std::cout << "It costs " << cost << " dollars to ship a " << weight << " kilo package " << distance << " miles" << std::endl;
return 0;
}
Q3
// Lab 2 Q3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int main()
{
//ask the user for a subscription package
char package = 0;
std::cout << "Choose a package - A, B or C" << std::endl;
std::cin >> package;
if (!(package == 'A' || package == 'B' || package == 'C'))
{
// exit on an invalid selection, because we haven't covered while loops...
std::cout << "invalid selection";
return 0;
}
//ask for number of minutes
//they shouldn't be less than 0 but that isn't in the specificaiton
double minutes = 0;
std::cout << "Enter number of minutes used" << std::endl;
std::cin >> minutes;
double totalCost = 0;
//calculate the charges based on the package and the minutes.
if (package == 'A')
{
//first calculate overage, if there is any
double overage = minutes - 450;
if (overage < 0)
{
overage = 0;
}
// add the base rate and the overage charge to get the total cost
totalCost = 39.99 + overage*0.45;
}
else if (package == 'B')
{
//first calculate overage, if there is any
double overage = minutes - 900;
if (overage < 0)
{
overage = 0;
}
// add the base rate and the overage charge to get the total cost
totalCost = 59.99 + overage*0.40;
}
else // package == C
{
totalCost = 69.99;
}
//display the charges
std::cout << "The total charges are " << totalCost << " dollars" << std::endl;
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.