0% found this document useful (0 votes)
8 views10 pages

Lab6 2

Uploaded by

hammy1500d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Lab6 2

Uploaded by

hammy1500d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

LAB 6.

5
Exercise 1:

GLOBAL Main Main Inner 1 Main Inner 2 AREA

PI radius area circumferen rad length


ce
RATE PI radius radius answer distance

RATE PI PI area circumferenc


e
RATE RATE radius radius

PI PI

RATE RATE

Circumference

Exercise 2&3:

Code:

#include <iostream>
#include <iomanip>
using namespace std;

// PARASPREET SINGH

const double PI = 3.14;


const double RATE = 0.25;

void findArea(float, float&);


void findCircumference(float, float&);

int main()
{
cout << fixed << showpoint << setprecision(2);
float radius = 12;

cout << " Main function outer block" << endl;


cout << " PI, RATE and radius are active here" << endl << endl;

{
float area;

cout << "Main function first inner block" << endl;


cout << " PI, RATE, radius and area are active here" << endl << endl;

findArea(radius , area);

cout << "The radius = " << radius << endl;


cout << "The area = " << area << endl << endl;
}

{
float radius = 10;
float circumference;

cout << "Main function second inner block" << endl;


cout << "PI, RATE, radius and circumference are active here" << endl <<
endl;

findCircumference(radius, circumference);

cout << "The radius = " << radius << endl;


cout << "The circumference = " << circumference << endl << endl;
}

cout << "Main function after all the calls" << endl;
cout << "PI, RATE and radius are active here" << endl << endl;

return 0;
}

void findArea(float rad, float& answer)


{
cout << "AREA FUNCTION" << endl << endl;
cout << "PI, RATE, area, radius, rad and answer are active here" << endl <<
endl;

answer= PI * rad * rad;


}

void findCircumference(float length, float& distance)


{
cout << "CIRCUMFERENCE FUNCTION" << endl << endl;
cout << "PI, RATE, circumference, radius, lenght and distance are active here"
<< endl << endl;
distance = 2 * PI * length;
}
Exercise 4:

Radius passed by first inner main block:

12

Radius passed by second inner main block:

10

Exercise 5:

Output;
LAB 6.6

Exercise 1:

Expected Results:

We will now add 95 cents to our dollar total

We have added another $0.95 to our total

Our total so far is $0.95

The value of our local variable total is $0.95

Converting cents to dollars resulted in 0.95 dollars

We will now add 193 cents to our dollar total

We have added another $1.93 to our total

Our total so far is $2.88

The value of our local variable total is $1.93

Converting cents to dollars resulted in 1.93 dollars

We will now add the default value to our dollar total

We have added another $1.50 to our total

Our total so far is $4.38

The value of our local variable total is $1.50

Converting cents to dollars resulted in 1.50 dollars

EXERCISE 2:

#include <iostream>
#include <iomanip>
using namespace std;

// PARASPREET SINGH
void normalizeMoney(float& dollars, int cents = 150);

int main()
{
int cents;
float dollars;

cout << setprecision(2) << fixed << showpoint;

cents = 95;
cout << "\n We will now add 95 cents to our dollar total\n";

normalizeMoney(dollars, cents);
cout << "Converting cents to dollars resulted in " << dollars << " dollars\n";

cout << "\n We will now add 193 cents to our dollar total\n";

normalizeMoney(dollars, 193 );

cout << "Converting cents to dollars resulted in " << dollars << " dollars\n";

cout << "\n We will now add the default value to our dollar total\n";

normalizeMoney(dollars);
cout << "Converting cents to dollars resulted in " << dollars << " dollars\n";

return 0;
}

void normalizeMoney(float& dollars, int cents)


{
float total = 0;

static float sum = 0.0;

dollars = static_cast< float>(cents)/100;

total = total + dollars;


sum = sum + dollars;

cout << "We have added another $" << dollars << " to our total" << endl;
cout << "Our total so far is $" << sum << endl;

cout << "The value of our local variable total is $" << total << endl;
}

OUTPUT:
LAB 6.7
Exercise 1:

If you will run the program like this incompletely, it will allow you to input the amount
but it will not show any result.

Exercise 2:

After completing the program,

Code:

#include <iostream>
#include <iomanip>
using namespace std;

// PARASPREET SINGH

void convertMulti(float dollars, float& euros, float& pesos);


void convertMulti(float dollars, float& euros, float& pesos, float& yen);
float convertToYen(float dollars, float& yen);
float convertToEuros(float dollars, float& euros);
float convertToPesos(float dollars, float&pesos);

int main()
{
float dollars;
float euros;
float pesos;
float yen;
cout << fixed << showpoint << setprecision(2);

cout << "Please input the amount of American Dollars you want converted "
<< endl;
cout << "to euros and pesos" << endl;
cin >> dollars;

convertMulti(dollars,euros,pesos);// Fill in the code to call convertMulti


with parameters dollars, euros, and pesos

cout<<"$"<< dollars <<" is converted to " << pesos << " pesos and " << euros
<< " euros \n ";// Fill in the code to output the value of those dollars converted
to both euros
// and pesos

cout << "Please input the amount of American Dollars you want converted\n";
cout << "to euros, pesos and yen" << endl;
cin >> dollars;

convertMulti (dollars, euros,pesos, yen );// Fill in the code to call


convertMulti with parameters dollars, euros, pesos and yen

cout<<"$ "<< dollars <<" is converted to " << yen<< " yen" <<" and " << euros
<< " euros and "<< pesos <<" pesos \n";// Fill in the code to output the value of
those dollars converted to euros,
// pesos and yen

cout << "Please input the amount of American Dollars you want converted\n";
cout << "to yen" << endl;
cin >> dollars;

convertToYen (dollars, yen);// Fill in the code to call convertToYen

cout<<"$ "<< dollars <<" is converted to " << yen<< " yen" << endl;// Fill in
the code to output the value of those dollars converted to yen

cout << "Please input the amount of American Dollars you want converted\n";
cout << " to euros" << endl;
cin >> dollars;

convertToEuros(dollars, euros);// Fill in the code to call convert ToEuros

cout<<"$ "<< dollars <<" is converted to " << euros << " euros \n ";// Fill in
the code to output the value of those dollars converted to euros

cout << "Please input the amount of American Dollars you want converted\n";
cout << " to pesos " << endl;
cin >> dollars;

convertToPesos(dollars, pesos);// Fill in the code to call convertToPesos

cout<<"$ "<< dollars <<" is converted to " << pesos << " pesos \n ";// Fill in
the code to output the value of those dollars converted to pesos
return 0;
}

// All of the functions are stubs that just serve to test the functions
// Replace with code that will cause the functions to execute properly

// **************************************************************************
// convertMulti
//
// task: This function takes a dollar value and converts it to euros
// and pesos
// data in: dollars
// data out: euros and pesos
//
// *************************************************************************

void convertMulti(float dollars, float& euros, float& pesos)


{
cout << "The function convertMulti with dollars, euros and pesos "
<< endl << " was called with " << dollars << " dollars" << endl << endl;
euros = 1.06 * dollars;
pesos= 9.73 * dollars;
}

// ************************************************************************
// convertMulti
//
// task: This function takes a dollar value and converts it to euros
// pesos and yen
// data in: dollars
// data out: euros pesos yen
//
// ***********************************************************************

void convertMulti(float dollars, float& euros, float& pesos, float& yen)


{
cout << "The function convertMulti with dollars, euros, pesos and yen"
<< endl << " was called with " << dollars << " dollars" << endl << endl;
euros = 1.06 * dollars;
pesos= 9.73 * dollars;
yen= 124.35 *dollars;
}

// ****************************************************************************
// convertToYen
//
// task: This function takes a dollar value and converts it to yen
// data in: dollars
// data returned: yen
//
// ***************************************************************************

float convertToYen(float dollars, float& yen)


{
cout << "The function convertToYen was called with " << dollars << " dollars"
<< endl << endl;
yen= 124.35 * dollars;
return 0;
}

// ****************************************************************************
// convertToEuros
//
// task: This function takes a dollar value and converts it to euros
// data in: dollars
// data returned: euros
//
// ****************************************************************************

float convertToEuros(float dollars, float& euros)


{
cout << "The function convertToEuros was called with " << dollars
<< " dollars" << endl << endl;
euros = 1.06 * dollars;
return 0;
}

// *****************************************************************************
// convertToPesos
//
// task: This function takes a dollar value and converts it to pesos
// data in: dollars
// data returned: pesos
//
// ****************************************************************************

float convertToPesos(float dollars, float& pesos)


{
cout << "The function convertToPesos was called with " << dollars
<< " dollars" << endl;
pesos= 9.73 * dollars;
return 0;
}

Output:

You might also like