0 votes
84 views
in Practical Questions by (98.9k points)
Practical session(binary, ratio/reciprocal, circle area & circumference) Upload ur program code and output. If any compilation errors(try to resolve them) do upload the code atleast.

1 Answer

0 votes
by (98.9k points)

I'd be happy to help you with practical sessions on binary operations, ratios and reciprocals, and circle area and circumference. Let's go through each of these topics step by step.

1. Binary Operations: Binary operations involve performing mathematical operations on two operands. Common binary operations include addition, subtraction, multiplication, and division.  

 

#include <iostream>

int main() {
    // Binary addition
    int binary1, binary2;
    std::cout << "Enter first binary number: ";
    std::cin >> binary1;
    std::cout << "Enter second binary number: ";
    std::cin >> binary2;

    int result_add = binary1 + binary2;
    std::cout << "Binary Addition: " << result_add << std::endl;

    // Binary subtraction
    int binary3, binary4;
    std::cout << "Enter first binary number: ";
    std::cin >> binary3;
    std::cout << "Enter second binary number: ";
    std::cin >> binary4;

    int result_sub = binary3 - binary4;
    std::cout << "Binary Subtraction: " << result_sub << std::endl;

    // Binary multiplication
    int binary5, binary6;
    std::cout << "Enter first binary number: ";
    std::cin >> binary5;
    std::cout << "Enter second binary number: ";
    std::cin >> binary6;

    int result_mul = binary5 * binary6;
    std::cout << "Binary Multiplication: " << result_mul << std::endl;

    // Binary division
    int binary7, binary8;
    std::cout << "Enter dividend (binary): ";
    std::cin >> binary7;
    std::cout << "Enter divisor (binary): ";
    std::cin >> binary8;

    int result_div = binary7 / binary8;
    std::cout << "Binary Division: " << result_div << std::endl;

    return 0;
}
 

 

2. Ratios and Reciprocals: Ratios express the relationship between two quantities. Reciprocals are the multiplicative inverses of numbers.  

 

 

#include <iostream>

int main() {
    // Printing rate calculation
    int pages, time_minutes;
    std::cout << "Enter number of pages: ";
    std::cin >> pages;
    std::cout << "Enter time in minutes: ";
    std::cin >> time_minutes;

    double printing_rate = static_cast<double>(pages) / time_minutes;
    double reciprocal_rate = 1.0 / printing_rate;
    std::cout << "Printing Rate: " << printing_rate << " pages per minute" << std::endl;
    std::cout << "Reciprocal Rate: " << reciprocal_rate << " minutes per page" << std::endl;

    // Ratio and reciprocal
    int boys, girls;
    std::cout << "Enter number of boys: ";
    std::cin >> boys;
    std::cout << "Enter number of girls: ";
    std::cin >> girls;

    double ratio = static_cast<double>(boys) / girls;
    double reciprocal_ratio = 1.0 / ratio;
    std::cout << "Ratio of Boys to Girls: " << ratio << std::endl;
    std::cout << "Reciprocal Ratio: " << reciprocal_ratio << std::endl;

    return 0;
}
 

3. Circle Area and Circumference: Circle area and circumference are fundamental concepts in geometry. The area of a circle is given by πr^2, and the circumference is given by 2πr, where r is the radius.  

#include <iostream>
#include <cmath>

int main() {
    // Circle calculations
    double radius1;
    std::cout << "Enter radius of Circle 1: ";
    std::cin >> radius1;

    double area1 = M_PI * radius1 * radius1;
    double circumference1 = 2 * M_PI * radius1;
    std::cout << "Circle 1 - Area: " << area1 << ", Circumference: " << circumference1 << std::endl;

    double diameter;
    std::cout << "Enter diameter of Circle 2: ";
    std::cin >> diameter;

    double radius2 = diameter / 2.0;
    double area2 = M_PI * radius2 * radius2;
    double circumference2 = 2 * M_PI * radius2;
    std::cout << "Circle 2 - Area: " << area2 << ", Circumference: " << circumference2 << std::endl;

    return 0;
}
 

Related questions

0 votes
1 answer 114 views
0 votes
1 answer 101 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...