Concept explainers
*Construct a flowchart for Base Conversion Module to illustrate the codes below.*
#include <iostream>
using namespace std;
int octal(int deciNum)
{
int octalNum = 0, countval = 1;
int dNo = deciNum;
while (deciNum != 0) {
// decimals remainder is calculated
int remainder = deciNum % 8;
// storing the octalvalue
octalNum += remainder * countval;
// storing exponential value
countval = countval * 10;
deciNum /= 8;
}
return octalNum;
}
string binary(int num)
{
string str;
while(num){
if(num & 1) // 1
str+='1';
else // 0
str+='0';
num>>=1; // Right Shift by 1
}
return str;
}
void reverse(string str)
{
for(int i=str.size()-1 ; i>=0 ; i--)
cout<< str[i];
}
int main()
{
int n;
char ch;
cout<<"Enter the decimal number: ";
cin>>n;
cout<<"Enter b for binary, o for octal: ";
cin>>ch;
if(ch=='b'){
cout<<"Binary of "<<n<<" is ";
reverse(binary(n));}
else if(ch=='o')
cout<<"Octal of "<<n<<" is "<<octal(n);
else
cout<<"Invalid choice";
return 0;
}
Step by stepSolved in 4 steps with 7 images
- ê #include using namespace std; int main() { int count = 5; int num = 2; while (count r && num ){ cout << count << " " << num << endl; count -=1; if (count % 2 == 0) num -=1; } return 0; Output: 52 4 1 3 1 20 10arrow_forward// LargeSmall.cpp - This program calculates the largest and smallest of three integer values. #include <iostream> using namespace std; int main() { // This is the work done in the housekeeping() function // Declare and initialize variables here int largest; // Largest of the three values int smallest; // Smallest of the three values // Prompt the user to enter 3 integer values // Write assignment, add conditional statements here as appropriate // This is the work done in the endOfJob() function // Output largest and smallest number. cout << "The largest value is " << largest << endl; cout << "The smallest value is " << smallest << endl; return 0; }arrow_forward#include using namespace std; Type the program's output int main() { int g; g = 0; while (g >= −2) { } cout << g << endl; g = g - 1; return 0;arrow_forward
- #include <iostream> #include <cmath> using namespace std; // declare functions void display_menu(); void convert_temp(); double to_celsius(double fahrenheit); double to_fahrenheit(double celsius); int main() { cout << "Convert Temperatures\n\n"; display_menu(); char again = 'y'; while (again == 'y') { convert_temp(); cout << "Convert another temperature? (y/n): "; cin >> again; cout << endl; } cout << "Bye!\n"; } // define functions void display_menu() { cout << "MENU\n" << "1. Fahrenheit to Celsius\n" << "2. Celsius to Fahrenheit\n\n"; } void convert_temp() { int option; cout << "Enter a menu option: "; cin >> option; double f = 0.0; double c = 0.0; switch (option) { case 1: cout << "Enter degrees Fahrenheit: "; cin >> f; c =…arrow_forward#include <iostream>#include <cmath>#include <iomanip>using namespace std; int main() { double x; double y; double z; cin >> x; cin >> y; /* Your code goes here */ cout << fixed << setprecision(1); // setprecision(1) outputs z with 1 decimal place. cout << z << endl; return 0;} having trouble with this code in C++arrow_forward#include<iostream> #include <cmath> using namespace std; int main() { float sp_Radius, sp_sa, sp_Volume; cout << "\nPlease Enter the radius of a Sphere = "; cin >> sp_Radius; sp_sa = 4 * M_PI * sp_Radius * sp_Radius; sp_Volume = (4.0/3) * M_PI * sp_Radius * sp_Radius * sp_Radius; cout << "\nThe Surface Area of a Sphere = " << sp_sa; cout << "\nThe Volume of a Sphere = " << sp_Volume; return 0; } C++ use this code and separate the program into three files. The main program containing the main function should be named main.cpp. The function definition file containing a function for the volume calculation and a function for the surface area calculation should be named SphereCalc.cpp. The function declaration file containing function declarations for the functions should be named SphereCalc.h. Make sure you include a Header Guard. Read the Radius from the Keyboard. If a negative number is provided, set the calculated value to zero.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education