Professional Documents
Culture Documents
Introduction
II. Pass-by-Reference
Example:
Example:
#include <iostream>
#include <math.h>
void GetSinCos(double dX, double &dSin, double &dCos)
{
dSin = sin(dX);
dCos = cos(dX);
}
int main()
{
double dSin = 0.0;
double dCos = 0.0;
GetSinCos(30.0, dSin, dCos);
This function takes one parameter (by value) as input, and “returns” two
parameters (by reference) as output.
Here is an example:
void pass(const int &x)
{
x = 6;
}
#include <iostream>
int main()
{
int x = 5;
return 0;
}
Another type of variable is the global variable. This variable has the
program scope wherein the variable can be used by any block within the
program. Because global variables have program scope, they can be used
across multiple files.
Here is an example:
#include <iostream>
Using namespace std;
Int y = 3;
int main()
{
int x = 5;
return 0;
}
Pseudo Code:
Start program
Initialize iostream, cstdlib, math.h, conio, iomanip
Declaration of Variables
Integers: choice, choice1, repick, repick1, select, C=0, n, t=0, X,
sum=0, row=0, column=0
Doubles: sample[11], cons[11], stat[10], matrixA[3][3],
matrixB[3][3], Xpow=0, ans=0, Constant, mean=0, sd=0,
x=0
Choices:
Print: Select the number you want to use:
1. Polynomial Evaluation
2. Statistical Algorithm
3. Matrix Operations
4. Exit
Select the task you want the program to do:
Input: choice1
If: choice1 = 1 or choice1 = 2 or choice1 = 3 or choice1 = 4
choice = choice1 and continue to case
If choice == Y
Clear screen
Go to Repeat1
Else if choice == N
Clear screen
Return to Choices
Else
Print “Wrong Choice Input! Choose the number correctly.”
“Press any key to continue!”
Go to Check1
If choice == Y
Clear screen
Go to Repeat2
Else if choice == N
Clear screen
Return to Choices
Else
Print “Wrong Choice Input! Choose the number correctly.”
“Press any key to continue!”
Go to Check2
Case 3: Matrix Operations
Repeat3:
Print: You have selected number 3 – Matrix Operations
Please input the row (max of 3):
Please input the column (max of 3):
Input matrix A’s row and column [m][n]:
Input matrix B’s row and column [m][n]:
Clear screen
Display Matrix A and Matrix B
Print: The Matrix Operations
1. Addition
2. Multiplication
3. Transpose
4. Exit
If chosen 1. Addition,
Print: The answer is:
Display resulting matrix
Else if chosen 2. Multiplication,
Print: Please input the multiplier:
Display resulting matrix A and B
Else if chosen 3. Transpose,
Print: The Transpose of Matrix A and Matrix B:
Display Matrix A
Display Matrix B
Else if chosen 4. Exit,
Check3: Error for wrong input for (y/n)
Print: Do you want to solve another problem using Statistical
Algorithm? (Y/N)
1. Yes
2. No
Input:
Scan choice
If choice == Y
Clear screen
Go to Repeat3
Else if choice == N
Clear screen
Return to Choices
Else
Print “Wrong Choice Input! Choose the number correctly.”
“Press any key to continue!”
Go to Check3