0% found this document useful (0 votes)
64 views5 pages

Part B Input

The document contains C++ code that defines functions to draw different shapes by outputting text patterns to the console. The main function calls the three shape drawing functions. The first function draws an N shape, the second draws an S shape, and the third draws an M shape.

Uploaded by

Ng Siewmin
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)
64 views5 pages

Part B Input

The document contains C++ code that defines functions to draw different shapes by outputting text patterns to the console. The main function calls the three shape drawing functions. The first function draws an N shape, the second draws an S shape, and the third draws an M shape.

Uploaded by

Ng Siewmin
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/ 5

Part B

Question 1
Input
#include <iostream>
#include <iomanip>
using namespace std;

//FUNCTION PROTOTYPE
void draw_intersect(void);
void draw_horizontal(void);
void draw_parallel(void);

int main(void)
{
draw_intersect();
draw_horizontal();
draw_parallel();

return 0;

//DRAW INTERSECT
void draw_intersect(void)
{
cout << " /\\ \n";
cout << " / \\ \n";
cout << " / \\ \n";
}

//DRAW HORIZONTAL
void draw_horizontal(void)
{
cout << "--------\n";
}

//DRAW PARALLEL
void draw_parallel(void)
{
cout << "| |\n";
cout << "| |\n";
cout << "| |\n";
}
Output

Part B
Question 2
Input
#include <iostream>
#include <iomanip>

// defined constant for price per apple


#define PRICE_PER_APPLE 0.85
// defined constant for price per orange
#define PRICE_PER_ORANGE 1.00

using namespace std;

// function prototypes
void display_heading(void);
void display_apple_item(int qty, double total);
void display_orange_item(int qty, double total);
void display_grand_total(double grand_total);

int main(void)
{
int apple_qty, orange_qty;
double apple_total, orange_total, grand_total;

// get number of apples and oranges


cout << "Enter number of apples: ";
cin >> apple_qty;
cout << "Enter number of oranges: ";
cin >> orange_qty;

// compute total for apples and oranges


apple_total = apple_qty * PRICE_PER_APPLE;
orange_total = orange_qty * PRICE_PER_ORANGE;

// compute grand total


grand_total = apple_total + orange_total;

// write the function calls to display the result


display_heading();
display_apple_item(apple_qty, apple_total);
display_orange_item(orange_qty, orange_total);
display_grand_total(grand_total);

return 0;
}

void display_heading(void)
{
cout << "=========My Fruit Store========\n";
cout << "Fruit Qty Price Total\n";
cout << "-------------------------------\n";
}

void display_apple_item(int qty, double total)


{
cout << "Apple\t" << setw(3) << qty;
cout << " RM" << setw(4) << fixed << setprecision(2) << PRICE_PER_APPLE;
cout << "\tRM" << setw(5) << fixed << setprecision(2) << total << endl;
}

void display_orange_item(int qty, double total)


{
cout << "Orange\t" << setw(3) << qty;
cout << " RM" << setw(4) << fixed << setprecision(2) << PRICE_PER_ORANGE;
cout << "\tRM" << setw(5) << fixed << setprecision(2) << total << endl;
}
void display_grand_total(double total)
{
cout << "-------------------------------\n";
cout << "Total\t\t\tRM" << setw(5) << fixed << setprecision(2) << total << endl;
}

Output
Part D
Question 1
Input
#include <iostream>
#include <iomanip>
using namespace std;

//FUNCTION PROTOTYPE
void draw_first(void);
void draw_second(void);
void draw_third(void);

int main(void)
{
//WRITE THE FUNCTION CALLS TO DISPLAY THE FIGURES
draw_first();
draw_second();
draw_third();

return 0;
}

//DISPLAY FIRST
void draw_first(void)
{
cout << "N N\n";
cout << "NN N\n";
cout << "N N N\n";
cout << "N NN\n";
cout << "N N\n";
cout << endl;
}

//DISPLAY SECOND
void draw_second(void)
{
cout << "SSSSS\n";
cout << "S \n";
cout << "SSSSS\n";
cout << " S\n";
cout << "SSSSS\n";
cout << endl;
}

//DISPLAY THIRD
void draw_third(void)
{
cout << "M M\n";
cout << "MM MM\n";
cout << "M M M\n";
cout << "M M\n";
cout << "M M\n";

Output

You might also like