开发者

c++ program can you help me

I need code to The solution of this problems Use Microsoft Visual Studio 6.0

Problem 1:

Write a complete C++ program that takes five floats A, B, C, D, and E and reorders them such that the smallest number is stored in A, and the largest number in E. Assume that t开发者_运维百科he Five numbers are distinct (different). The program reads five floats from the keyboard then reorder them. The program should then print the values of A, B, C, D, and E after the Reorder.

Problem 2:

Write a C++ program that reads in one of two characters input by the user. If the user input C, the program should calculate the area of a circle of radius input by the user. If the user inputs R, the program calculates the area of the rectangle of width and length input by the user.

Problem 3:

Write a C++ program that finds the roots of a second order equation (if they exist).

The equation will be:

a(X^2)+bX+c, the user will input the coefficients a, b, c. The program will first determine if the equation has roots or not. If it does, then the program will find these roots and display to the user:

a(X^2)+bX+c=(X-R1)+(X-R2) where R1 and R2 are the roots of the equation.


First program:

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{

    float A,B,C,D,E;
    float b,c,d,e;

    cout<<"This program takes 5 float inputs,reorder then print them";
    cout<<"\n Enter the first float";
    cin>>A;
    cout<<"\n Enter the first float";
    cin>>b;
    if (b>A){ 
        B=A;
        A=b;
    }
    else B=b;

    cout<<"\n Enter the second float";
    cin>>c;
    if (c>A){
        C=B;
        B=A;
        A=c;
    }
    else if (c>B){
        C=B;
        B=c;
    }
    else C=c;
    cout<<"\n Enter the third float";
    cin>>d;
    if (d>A){
        D=C;
        C=B;
        B=A;
        A=d;
    }
    else if (d>B){
        D=C;
        C=B;
        B=d;
    }
    else if(d>C){
        D=C;
        C=d;
    }
    cout<<"\n Enter the fourth float";
    cin>>e;
    if(e>A){
        E=D;
        D=C;
        C=B;
        B=A;
        A=e;
    }
    else if(e>B){
        E=D;
        D=C;
        C=B;
        B=e;
    }
    else if(e>C){
        E=D;
        D=C;
        C=e;
    }
    else if(e>D){
        E=D;
        D=e;
    }
    cout<<A<<"\t"<<B<<"\t"<<C<<"\t"<<D<<"\t"<<E;
    return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜