Lab 2 Solution

$29.99 $18.99

Introduction: In last week’s lab we learned how to define variables and how to use expressions to modify the values stored in those variables. Many times when we write code we need the execution of that code to depend on a defined condition. These techniques are called ​Branching ​because they produce code whose execution splits…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

Rate this product

Introduction:

In last week’s lab we learned how to define variables and how to use expressions to modify the values stored in those variables. Many times when we write code we need the execution of that code to depend on a defined condition. These techniques are called Branching because they produce code whose execution splits into different paths of execution based on conditions we define. C++ provides the if, else if, and else statements​​for branching.

The purpose of this lab is to familiarize you with Branching.

Directions:

1- Launch Code::Blocks and start a new file. Name it your_last_name_lab2.cpp.

2-Include the standard header for this lab:

//Your Name

//CS1428

//Lab 2

3- Include the iostream standard library and start your main function:

#include <iostream>

using namespace std;

int main() {

4- Declare the following variables:

  1. An integer called myCount.

  1. A boolean called myCondition.

  1. Assign appropriate values to myCount and myCondition.

5- Practice branching by copying the following code:

9- Do not copy the following code.Instead, predict the value of the int outputValue after the following code has executed. Print your prediction in the console with a cout statement.

bool a = true;

int b = 1, c = 2, outputValue = 0;

if(b < = c){

a = false;

}

else{

b = 3;

}

if(a){

b = c;

}

else{

c=b;

}

if(c==1){

outputValue = 100 * c;

}

else {

outputValue = 100 * b;

}

Notice that using one character variable names makes code hard to read and is generally a bad idea.

10- Save your work. Build and Run your code. Fix any errors. Your output should be something like this:

11- Submit you .cpp file through TRACS as an attachment. You can leave when you’re done.