Question

**Please write a C++ program

**I'd appreciate it if you could take a screenshot/picture and put it up

Thanks

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

C++ Program to Calculate Solutions to Quadratic Equations:

#include<bits/stdc++.h>
using namespace std;
int main() {
float a, b, c, x1, x2, D, real, imaginary;
cout << "Enter values of a, b and c: ";
cin >> a >> b >> c;
D = b*b - 4*a*c;
  
if (D >= 0) {
x1 = (-b + sqrt(D)) / (2*a);
x2 = (-b - sqrt(D)) / (2*a);
cout<<"Solutions are: "<<x1<<" & "<<x2<<endl;
}
else {
real = -b/(2*a);
imaginary =sqrt(-D)/(2*a);
cout << "Solutions are " << real << "+" << imaginary << "i" <<" & "<< real << "-" <<imaginary << "i" << endl;
}
return 0;
}

C++ Program for Unit Conversion:

#include<bits/stdc++.h>
using namespace std;
int main() {
   float mag;

   cout<<"Enter the magnitude: ";
   cin>>mag;
cout<<"Enter which unit you want to convert{ou,gal,oz,lb,in}: ";
char s[5];
cin>>s;
cout<<"Enter which unit you want to convert to{ml,l,g,kg,mm,cm,m,km}: ";
char r[5];
cin>>r;
if(strcmp(s,"ou")==0)
{
   if(strcmp(r,"ml")==0)
   {
       cout<<mag<<" Ounce = "<<29.586*mag<<" milliliter "<<endl;
       }
       else if(strcmp(r,"l")==0)
       {
           cout<<mag<<" Ounce = "<<(29.586*mag)/1000.0<<" liter "<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
else if(strcmp(s,"gal")==0)
{
       if(strcmp(r,"ml")==0)
   {
       cout<<mag<<" galoon = "<<3.785*mag*1000<<" milliliter "<<endl;
       }
       else if(strcmp(r,"l")==0)
       {
           cout<<mag<<" galoon = "<<(3.785*mag)<<" liter "<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
   else if(strcmp(s,"lb")==0)
   {
           if(strcmp(r,"g")==0)
   {
       cout<<mag<<" Pound = "<<453.6*mag<<" grams"<<endl;
       }
       else if(strcmp(r,"kg")==0)
       {
           cout<<mag<<" Pound = "<<(453.6*mag)/1000.0<<" Kilogram "<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
   else if(strcmp(s,"oz")==0)
   {
           if(strcmp(r,"g")==0)
   {
       cout<<mag<<" ounce = "<<28.3495*mag<<" grams"<<endl;
       }
       else if(strcmp(r,"kg")==0)
       {
           cout<<mag<<" ounce = "<<(28.3495*mag)/1000.0<<" Kilogram "<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
   else if(strcmp(s,"in")==0)
   {
           if(strcmp(r,"cm")==0)
   {
       cout<<mag<<" inch = "<<2.54*mag<<" centimeters"<<endl;
       }
       else if(strcmp(r,"m")==0)
       {
           cout<<mag<<" inch = "<<(2.54*mag)/100.0<<" neter "<<endl;
       }
       else if(strcmp(r,"km")==0)
       {
           cout<<mag<<" inch ="<<(2.54*mag)/10000.0<<" kilometer"<<endl;
       }
       else if(strcmp(r,"mm")==0)
       {
           cout<<mag<<" inch = "<<(2.54*mag)*10<<" millimeter "<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
  
   else if(strcmp(s,"ft")==0)
   {
           if(strcmp(r,"cm")==0)
   {
       cout<<mag<<" foot = "<<30.5*mag<<" centimeters"<<endl;
       }
       else if(strcmp(r,"m")==0)
       {
           cout<<mag<<" foot = "<<(30.5*mag)/100.0<<" meter "<<endl;
       }
       else if(strcmp(r,"km")==0)
       {
           cout<<mag<<" foot ="<<(30.5*mag)/100000.0<<" kilometer"<<endl;
       }
       else if(strcmp(r,"cm")==0)
   {
       cout<<mag<<" foot = "<<30.5*mag*10<<" millimeters"<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
  
   else if(strcmp(s,"mi")==0)
   {
           if(strcmp(r,"cm")==0)
   {
       cout<<mag<<" mile = "<<1.609*mag*100000.0<<" centimeters"<<endl;
       }
       else if(strcmp(r,"m")==0)
       {
           cout<<mag<<" mile = "<<(1.609*mag)*1000.0<<" meter "<<endl;
       }
       else if(strcmp(r,"km")==0)
       {
           cout<<mag<<" mile ="<<(1.609*mag)<<" kilometer"<<endl;
       }
       else if(strcmp(r,"cm")==0)
   {
       cout<<mag<<" mile = "<<1.609*mag*1000000.0<<" millimeters"<<endl;
       }
       else
       {
           cout<<"Invalid Conversion"<<endl;
       }
   }
   else
   {
       cout<<"Invalid Input"<<endl;
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
**Please write a C++ program **I'd appreciate it if you could take a screenshot/picture and put...
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
  • Coding in C# please Develop the C# program for the following problems: 1. Create a new...

    Coding in C# please Develop the C# program for the following problems: 1. Create a new class and name it as Conversion. 2. In this class, provide the code that uses a for or while loop to display a table that lists values for some unit and the equivalent in two other units. . Enter a start value, and end value and a step value as a range of values for the unit to be converted, . Show three columns...

  • C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it...

    C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it should convert 14:25 to 2:25 PM. The input is given as two integers. There should be at least three functions, one for input, one to do the conversion, and two for output (one for 12-hour time and another for 24-hour time). Record the AM/PM information as a value of type char, ‘A’ for AM and ‘P’ for PM. Thus, the function for doing the...

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