cpp codes example (strings arrays.. 2 )

Lab 3
Q1
// Question 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <math.h>
#define PI 3.141592


int main()
{
int initialRadius = 0;
std::cout << "initial radius : ";
std::cin >> initialRadius;

int increment = 0;
std::cout << "increment : ";
std::cin >> increment;

int finalRadius = 0;
std::cout << "final radius : ";
std::cin >> finalRadius;

std::cout << std::endl;

for (int radius = initialRadius; radius <= finalRadius; radius += increment)
{
std::cout << "The volume of a sphere with a radius of " << radius << " is " << (4.0 / 3.0)*PI*pow(radius, 3) << std::endl;
}

return 0;
}


Assignment 1 Q1
// A1 Q1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int main()
{
int temperature = 0;
std::cout << "Enter a temperature : ";
std::cin >> temperature;

if (temperature <= -173)
{
std::cout << "Ethyl alcohol will freeze at that temperature" << std::endl;
}
if (temperature <= -38)
{
std::cout << "Mercury will freeze at that temperature" << std::endl;
}
if (temperature <= -362)
{
std::cout << "Oxygen will freeze at that temperature" << std::endl;
}
if (temperature <= 32)
{
std::cout << "Water will freeze at that temperature" << std::endl;
}
if (temperature >= 172)
{
std::cout << "Ethyl alcohol will boil at that temperature" << std::endl;
}
if (temperature >= 676)
{
std::cout << "Mercury will boil at that temperature" << std::endl;
}
if (temperature >= -306)
{
std::cout << "Oxygen will boil at that temperature" << std::endl;
}
if (temperature >= 212)
{
std::cout << "Water will boil at that temperature" << std::endl;
}

return 0;
}



Q2

// A1 Q2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int main()
{
int store1 = 0;
std::cout << "Enter store 1 sales : ";
std::cin >> store1;

int store2 = 0;
std::cout << "Enter store 2 sales : ";
std::cin >> store2;

int store3 = 0;
std::cout << "Enter store 3 sales : ";
std::cin >> store3;

int store4 = 0;
std::cout << "Enter store 4 sales : ";
std::cin >> store4;

int store5 = 0;
std::cout << "Enter store 5 sales : ";
std::cin >> store5;

std::cout << std::endl;

std::cout << "SALES BAR CHART" << std::endl;
std::cout << "(Each * = $100)" << std::endl;

std::cout << "Store 1: ";
for (int sales = 0; sales < store1 / 100; sales++)
{
std::cout << "*";
}
std::cout << std::endl;

std::cout << "Store 2: ";
for (int sales = 0; sales < store2 / 100; sales++)
{
std::cout << "*";
}
std::cout << std::endl;

std::cout << "Store 3: ";
for (int sales = 0; sales < store3 / 100; sales++)
{
std::cout << "*";
}
std::cout << std::endl;

std::cout << "Store 4: ";
for (int sales = 0; sales < store4 / 100; sales++)
{
std::cout << "*";
}
std::cout << std::endl;

std::cout << "Store 5: ";
for (int sales = 0; sales < store5 / 100; sales++)
{
std::cout << "*";
}
std::cout << std::endl;

return 0;
}


A2 Q1
// Assignment A2 Q1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#define PI 3.141592

double getInput();

double calcXc(double capacitance, double frequency);

void print(double capacitance, double frequency, double reactance);

int main()
{
std::cout << "Input the capacitance in Farads" << std::endl;
double capacitance = getInput();

std::cout << "Input the frequency in Hertz" << std::endl;
double frequency = getInput();

double reactance = calcXc(capacitance, frequency);

print(capacitance, frequency, reactance);

return 0;
}

double getInput()
{
double input = 0;
std::cin >> input;
return(input);
}

double calcXc(double capacitance, double frequency)
{
return(1.0/(2*PI*frequency*capacitance));
}

void print(double capacitance, double frequency, double reactance)
{
std::cout << "The capacitance is " << capacitance << " Farads" << std::endl;
std::cout << "The frequency is " << frequency << " Hertz" << std::endl;
std::cout << "The reactance is " << reactance << " Ohms" << std::endl;
}



A2 Q2
// Assignment A2 Q2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

void displayUsage();

void inputCalc();

void calcBillDisplay(int numDays, double surgeryCost, double medCost, double miscCost, double costPerDay, double insuranceDeductible);

void display(double totalCost, double costLessDeductible, double costLessMedsDeductible);


int main()
{
displayUsage();
inputCalc();

return 0;
}

void displayUsage()
{
std::cout << "This program will calculate your hospital bill..." << std::endl << std::endl;
}

void inputCalc()
{
int numDays = 0;
double surgeryCost = 0;
double medCost = 0;
double miscCost = 0;
double costPerDay = 0;
double insuranceDeductible = 0;

std::cout << "Input Number of Days ";
std::cin >> numDays;
std::cout << "Input Surgery Cost ";
std::cin >> surgeryCost;
std::cout << "Input Meds Cost ";
std::cin >> medCost;
std::cout << "Input Miscellaneous Cost ";
std::cin >> miscCost;
std::cout << "Input Costs Per Day ";
std::cin >> costPerDay;
std::cout << "Input Insurance Deductible ";
std::cin >> insuranceDeductible;

calcBillDisplay(numDays, surgeryCost, medCost, miscCost, costPerDay, insuranceDeductible);
}

void calcBillDisplay(int numDays, double surgeryCost, double medCost, double miscCost, double costPerDay, double insuranceDeductible)
{
double totalCost = (double)numDays*costPerDay + surgeryCost + medCost + miscCost + insuranceDeductible;
double costLessDeductible = totalCost - insuranceDeductible;
double costLessMedsDeductible = costLessDeductible - medCost;

display(totalCost, costLessDeductible, costLessMedsDeductible);
}

void display(double totalCost, double costLessDeductible, double costLessMedsDeductible)
{
std::cout << std::endl << "Total Cost is " << totalCost << std::endl;
std::cout << "Cost Less Deductible is " << costLessDeductible << std::endl;
std::cout << "Cost Less Meds and Deductible is " << costLessMedsDeductible;
}



Topic archived. No new replies allowed.