C++
int number;
number = 1;
while (number < 11)
{
number = number + 1;
cout << number << endl;
}
12. What is the output for the following loop?
int number;
bool done;
number = 2;
done = FALSE;
while (!done)
{
number = number * 2;
if (number > 12)
done = TRUE;
cout << number << endl;
}


Code
to Copy:
// Include the required header file.
#include <iostream>
using namespace std;
// Start of the main() function.
int main()
{
// Declare an integer variable to store user input.
int num;
// Declare and initialize variables to hold the value
// of square and cube of input number.
int square=0, cube=0;
// Prompt the user to input a number.
cout << "\n Enter a number : ";
cin >> num;
// While loop to continues to execute until input
// number is 999.
while(num!=999)
{
// Display the number entered by the user.
cout<< "\n Entered number is "<<num;
// Calculate and display the square of a number.
square=num*num;
cout << "\n The square of the number "<<num<<" is "<<square;
// Calculate and display the cube of a number
cube=num*num*num;
cout<< "\n The cube of the number "<<num<<" is "<<cube<<endl;
// Prompt the user to continue the operation or
// stops the operation by entering 999.
cout<< "\n Enter a number [999 to exit] : ";
cin >> num;
// End of while loop
}
return 0;
// End of the main() function.
}



Code
to Copy:
// Include the required header file.
#include <iostream>
using namespace std;
// Start of the main() function.
int main()
{
// Declare four integers variable to store the length,
// width, area and perimeter of a rectangle.
int len, width, area, perimeter;
// Prompt the user to input the length and width of
// a rectangle.
cout<< "Enter the length and width of a rectangle: ";
cin>>len>>width;
// While loop continues to execute until 0 is entered
// for either the length or the width.
while(len!=0 && width!=0)
{
// Calculate and display the area of a rectangle.
area=len*width;
cout<< "Area of a rectangle : "<<area;
// Calculate and display the perimeter of a
// rectangle.
perimeter=2*(len+width);
cout<< "\nPerimeter of a rectangle : " <<perimeter <<endl;
// Prompt the user to continue the operation or
// stops by entering 0 for either length or width.
cout<< "\nEnter the length and width of a rectangle [0 to exit]: ";
cin>>len>>width;
// End of while loop.
}
return 0;
// End of the main() function.
}






C++ Write code that will input a number and print the number, the square of the...
Create a C++ Console project called Lab3a and add the following source document rect_struct.cpp to the project. #include <iostream> #include <iomanip> using namespace std; // This program uses a structure to hold data about a rectangle // PLACE YOUR NAME HERE // Fill in code to declare a structure named rectangle which has // members length, width, area, and perimeter all of which are floats int main() { // Fill in code to define a rectangle variable named box...
C++ Programming Code Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except to add documentation and your name. Please use the file names listed below since your file will have the following components: Ch16_Ex5_MainProgram.cpp - given file //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 #include <iostream> #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList<int> list, subList; int num; cout << "Enter...
Task:
Tasks to complete:
------------------------------------------------------------------------------------------------------------------------------------------
given code:
------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include
#include "rectangleType.h"
using namespace std;
// part e
int main()
{
rectangleType rectangle1(10, 5);
rectangleType rectangle2(8, 7);
rectangleType rectangle3;
rectangleType rectangle4;
cout << "rectangle1: " << rectangle1 <<
endl;
cout << "rectangle2: " << rectangle2 <<
endl;
rectangle3 = rectangle1 + rectangle2;
cout << "rectangle3: " << rectangle3 << endl;
rectangle4 = rectangle1 * rectangle2;
cout << "rectangle4: " << rectangle4 << endl;
if (rectangle1 > rectangle2)
cout << "Area...
Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...
C++ program.
int main()
{
Rectangle box; // Define an
instance of the Rectangle class
double rectWidth; // Local variable for width
double rectLength; // Local variable for length
string rectColor;
// Get the rectangle's width and length from the
user.
cout << "This program will calculate the area of
a\n";
cout << "rectangle. What is the width? ";
cin >> rectWidth;
cout << "What is the length? ";
cin >>...
12. Write a C function void rect(int *ar, int *per, int len, int wid) that computes the area ar and perimeter per of a rectangle with length len and width wid. Test it with a main program that inputs the length and width of a rectangle and outputs its area and perimeter. Output the value in the main program, not in the procedure. Sample Input 6 10 Sample Output Length: 6 Width: 10 Area: 60 Perimeter: 32
// This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp" #include <iostream> using namespace std; int main() { Rectangle rectangle1; Rectangle rectangle2; rectangle1.setLength(10.0); rectangle1.setWidth(5.0); rectangle2.setLength(7.0); rectangle2.setWidth(3.0); cout << "Perimeter of rectangle1 is " << rectangle1.calculatePerimeter() << endl; cout << "Area of rectangle1 is " << rectangle1.calculateArea() << endl; cout << "Perimeter of rectangle2 is " << rectangle2.calculatePerimeter() << endl; cout << "Area of rectangle2 is " << rectangle2.calculateArea() << endl;...
Write a c++ code into the given code to find composite numbers from the given random number list. The composite numbers is only counted once if there is a repeated number. I need to use this code and add on a code to find if the numbers generated is a composite function. Please help #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <vector> using namespace std; int main() { srand(time(NULL)); int size_of_list = 0; // the number of random...
In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...
Required in C++ I'm asked to: Print a histogram in which the
total number of times the dice rolls equals each possible value is
displayed by printing a character like * that number of times.
Below is my current code. I am not allowed to use arrays or
anything too advanced as I just started the class. I would really
appreciate the help as I've been stuck on it for a while now. I can
only get it to print...