Question

Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b):...

Use only if else nested if else only otherwise your answer won't be entertained.

Problem 1(b): Write a program that gives remainder without using modulus operator and loops. The first number entered will be dividend and second number entered will be divisor.

Sample input: 15 6

Sample output: Remainder is 3

In a right triangle, the square of the length of one side is equal to the sum of the squares of the length of the other two sides. Write a C++ program that takes in lengths of the three sides of a triangle, and then outputs whether the triangle is right or not.

 

Write a C++ program that asks a user to enter 2 numbers. Assign the numbers to integers ‘bigNumber’ and ‘littleNumber’. Check if bigNumber is not bigger than littleNumber. If yes, display “The littleNumber is bigger.” Else display “The bigNumber is bigger.”. Now check if they are evenly divisible.

If they are evenly divisible, display “They are evenly divisible” else display,” They are not evenly divisible”. If they are evenly divisible, check if they are the same number. If they are same, display “They are same” else, display “Not same”. 

The B's(AF) department of Must needs your help to assign Letter grades to newly admitted students. Write a C++ program that takes the marks of the student and display a letter grade according to the following rules. If a student takes marks greater than 85 out of 100 then he/she must be awarded A grade letter, if marks are between 75 and 85 out of 100 then you may assign the student grade B, for the range 65 to 75, C is given and for range 50 to 65 grade D will be awarded. For all marks obtained below 50 must be categorized as F grade. 

 

Write a C++ program that plays the game of “Rock, paper, scissors.” In this game, two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice dominates the other. The rules are: paper dominates (wraps) rock, rock dominates (breaks) scissors, and scissors dominate (cut) paper. Declares and initializes First player and second player variables at the start).

You can use ‘r’=rock, ‘p’=paper, ’s’=scissors

Examples:

First player = r

Second player = r

Output: Draw

First player = r

Second player = p

Output: 2nd player wins

Write a C++ program of a Body Mass Index (BMI) calculator application that reads the user’s weight and height and then calculates and displays the user’s body mass index. The formula for calculating BMI is:

English BMI Formula

BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703

Metric BMI Formula

BMI = ( Weight in Kilograms / ( Height in Meters x Height in Meters ) )

Also, the application should display the following information from the scale provided below.

BMI VALUES    Underweight: less than 18.5; Normal: between 18.5 and 24.9; Overweight: between 25 and 29.9; Obese: 30 or greater

Note: Your program should check that the height and weight entered are not negative. If the entered data is incorrect display a message accordingly.

People who deal with historical dates use a number called the Julian day to calculate the number of days between two events. The Julian day is the number of days that have elapsed since January 1, 4713 B.C. For example, the Julian day for October 16, 1956, is 2435763.

There are formulas for computing the Julian day from a given date, and vice versa. One very simple formula computes the day of the week from a given Julian day:

Day of the week = (Julian day + 1) % 7 where % is the modulus operator. This formula gives a result of 0 for Sunday, 1 for Monday, and so on, up to 6 for Saturday. For Julian day 2435763, the result is 2 (Tuesday). Your job is to write a C++ program that requests and inputs a Julian day, computes the day of the week using the formula, and then displays the name of the day that corresponds to that number.

Your output might look like this:

Enter a Julian day number and press Enter.

2451545

Julian day number 2451545 is a Saturday.

Enter a Julian day number and press Enter.

2451547

Julian day number 2451547 is a Monday.

 
Write a C++ program that takes an integer variable as input from user and checks whether the input is an even number and print the desired message

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


1)

#include <iostream>
#include <string>

using namespace std;

int main() {
   //Declaring variables
int a,b,first;
cout<<"Enter two numbers :";
cin>>a>>b;
first=a;
while(true)
{
   if(a-b>0)
   {
       a-=b;
       }
       else
       {
           break;
       }
   }
   cout<<"The Remainder when "<<first<<" is divided by "<<b<<" is :"<<a<<endl;
return 0;
}

_________________________

Output:

__________________________

2)

#include <iostream>
#include <cmath>

using namespace std;

bool isRightTriangle(int s1,int s2,int s3);
int main() {
   //Declaring variables
int s1,s2,s3;
cout<<"Enter 3 sides of the triangle (seperated by space ):"<<endl;
cin>>s1>>s2>>s3;
  
bool b=isRightTriangle(s1,s2,s3);
if(b)
{
   cout<<"The Triangle is Right angled"<<endl;
   }
   else
   {
   cout<<"The Triangle is not Right angled"<<endl;  
   }
return 0;
}
bool isRightTriangle(int s1,int s2,int s3)
{
   if((pow(s1,2)==pow(s2,2)+pow(s3,2))
   || (pow(s2,2)==pow(s3,2)+pow(s1,2))
   || (pow(s3,2)==pow(s1,2)+pow(s2,2)) )
   {
      return true;
   }
   else
   {
      return false;
   }
}

____________________________

Output:

______________________________

3)

#include <iostream>
#include <string>

using namespace std;

int main() {
   //Declaring variables
int bigNumber,littleNumber;
cout<<"Enter Big Number :";
cin>>bigNumber;
cout<<"Enter Little Number :";
cin>>littleNumber;
if(bigNumber<littleNumber)
{
   cout<<"The littleNumber is bigger."<<endl;
   }
   else
   {
       cout<<"The bigNumber is bigger."<<endl;
   }
  
   if(bigNumber%2==0 && littleNumber%2==0)
   {
       cout<<"They are evenly divisible"<<endl;
       if(bigNumber==littleNumber)
       {
           cout<<"They are same"<<endl;
       }
       else
       {
           cout<<"Not same"<<endl;
       }
   }
   else
   {
       cout<<"They are not evenly divisible"<<endl;
   }
  
return 0;
}

________________________________

Output:

_________________________________

4)

#include <iostream>
#include <string>

using namespace std;

int main() {
   //Declaring variables
int marks;
char letterGrade;
cout<<"Enter marks :";
cin>>marks;
  
if(marks>=85 && marks<=100)
{
   letterGrade='A';
   }
   else if(marks>=75 && marks<85)
{
   letterGrade='B';
   }
   else if(marks>=65 && marks<75)
{
   letterGrade='C';
   }
   else if(marks>=50 && marks<65)
{
   letterGrade='D';
   }
   else if(marks<50)
{
   letterGrade='F';
   }
  
   cout<<"Letter Grade :"<<letterGrade<<endl;
  

return 0;
}

____________________________

Output:

_____________________________

5)

#include <iostream>
#include <string>

using namespace std;

int main() {
   //Declaring variables
char p1,p2;
cout<<"‘r’=rock, ‘p’=paper, ’s’=scissors"<<endl;
cout<<"First player =";
cin>>p1;
cout<<"Second player =";
cin>>p2;

if(p1==p2)
{
    cout<<"Draw"<<endl;
   }
   else if(p1=='r' && p2=='p')
   {
      cout<<"2nd player wins"<<endl;
   }
   else if(p1=='p' && p2=='r')
   {
      cout<<"1st player wins"<<endl;
   }
   else if(p1=='r' && p2=='s')
   {
      cout<<"1st player wins"<<endl;
   }
   else if(p1=='s' && p2=='r')
   {
      cout<<"2nd player wins"<<endl;
   }
   else if(p1=='s' && p2=='p')
   {
      cout<<"1st player wins"<<endl;
   }
   else if(p1=='p' && p2=='s')
   {
      cout<<"2nd player wins"<<endl;
   }     

return 0;
}

______________________________

Output:

_________________________________

6)

#include <iostream>
#include <iomanip>
using namespace std;
// Function Declarations
string getCategory(double bmi);
double getBMI(double weight, int height);
double getBMIMeters(double kg,double meters);
int getValidNum();
int main() {
//Declaring variables
int feet,inches,choice;
double lbs,meters,kg,bmi,cms;
  
//setting the precision to two decimal places
std::cout << std::setprecision(2) << std::fixed;

//Displaying the Menu
cout<<":: MENU ::"<<endl;
cout<<"1. US Standard Measures"<<endl;
cout<<"2.International Metric Measures"<<endl;
cout<<"Enter Choice :";
cin>>choice;
if(choice==1)
{
cout<<"Enter Height in feet and inches (seperated by space):";
feet=getValidNum();
inches=getValidNum();
cout<<"Enter Weight (In pounds):";
lbs=getValidNum();
inches=feet*12+inches;
bmi=getBMI(lbs,inches);
cout<<setw(25)<<left<<"You weight is :"<<setw(30)<<lbs<<" lbs."<<endl;
cout<<setw(25)<<left<<"You height is :"<<setw(30)<<inches<<" inches."<<endl;
}
else if(choice==2)
{
cout<<"Enter Height (in centimeters) :";
cms=getValidNum();
cout<<"Enter Weight (in Kilograms):";
kg=getValidNum();
meters=(cms/100);
bmi=getBMIMeters(kg,meters);
cout<<setw(25)<<left<<"You weight is :"<<setw(30)<<left<<kg<<" kgs."<<endl;
cout<<setw(25)<<left<<"You height is :"<<setw(30)<<left<<cms<<" cms."<<endl;
  
}
else
{
cout<<"** Invalid Choice **"<<endl;
exit(0);
}
  
cout<<setw(25)<<left<<"You BMI is :"<<setw(30)<<bmi<<endl;
cout<<setw(25)<<left<<"You are :"<<setw(30)<<getCategory(bmi)<<endl;
  
return 0;
}
/* This method will the message based on
* calculate the BMI value
*/
string getCategory(double bmi)
{
string category;
if (bmi < 18.5)
category = "UnderWeight";
else if (bmi >= 18.5 && bmi <= 24.9)
category = "Normal";
else if (bmi >= 25 && bmi <= 29.9)
category = "OverWeight";
else if (bmi >= 30)
category = "Obese";
return category;
}
double getBMI(double weight, int height)
{
double bmi = (weight * 703) / (height * height);
// 703*weight/(height*height);
return bmi;
}
double getBMIMeters(double kg,double meters)
{
double bmi = kg/(meters*meters);
return bmi;
}
int getValidNum()
{
   int num;
   while(true)
   {
       cin>>num;
       if(num<=0)
       {
           cout<<"** Invalid.Must be greater than zero **"<<endl;
       }
       else
       {
           break;
       }
      
   }
   return num;
}

_____________________________

output#1:

_______________________

8)

#include <iostream>
#include <string>

using namespace std;

int main() {
   //Declaring variables
int num;
cout<<"Enter a number :";
cin>>num;
if(num%2==0)
{
    cout<<num<<" is an even number."<<endl;
   }
   else
   {
      cout<<num<<" is not an even number."<<endl;
   }
return 0;
}

___________________________

Output:

_______________________________Thank You

Add a comment
Know the answer?
Add Answer to:
Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b):...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help I am struggling with this and 3*Math.random())+1; and how to use it within the...

    Please help I am struggling with this and 3*Math.random())+1; and how to use it within the program For this project you will write a Java program that will play a simple game of Rock, Paper, Scissors.  If you have never played this game before the rules are simple - each player chooses one of Rock, Paper or Scissors and they reveal their choices simultaneously. • The choice of Rock beats the choice of Scissors ("Rock smashes Scissors") • The choice of...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....

  • SECTION B 80 MARKS QUESTION 1 12 marks Parents of the pupils of the Park Primary...

    SECTION B 80 MARKS QUESTION 1 12 marks Parents of the pupils of the Park Primary School must pay an amount for outfits for the annual play. All pupils take part in the play, except the Grade 0 pupils. The amount that the parents have to pay is calculated as follows: The cost of the outfits for Grade 1 and 2 pupils is R45 The cost of the outfits for Grades 3 to 5 is R65 Grade 6 and 7...

  • Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1...

    Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1 Semester: 403 Course Title Programming Submission 27-06-2020 Total Points 8 Date Submission Instructions: • This is an individual assignment. • Please submit your program (Java fle) in Blackboard. You can create one java project, named as Assignment1_id and add separate java file for each question. You can name your javá files as 01.02.... etc. • Make sure that you include your student ID name...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT