/** Copyright (c) 2013, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Qiu xuewei * Completion Date: July 15, May 20, 2013 * version: v1.0 * input Description: none * Problem description: Mona quadratic equation * program output: * Problem Analysis: * Algorithm Design: slightly * // * design a class of one-dimensional equation to obtain the solution of an equation, such as ax + B = 0. For example, when the input is 3x-8 = 0, the solution of the Output Equation is x = 2.66667. For example, when the input is 5 s + 18 = 0, the solution of the Output Equation is s =-3.6; */# include <iostream> using namespace std; class CEquation {public: CEquation (double a1 = 0, double b1 = 0); friend istream & operator> (istream & in, CEquation & c); friend ostream & operator <(ostream & output, CEquation & c); double solve (); char getx (); private: double a, B; double x; char s ;}; CEquation: CEquation (double a1, double b1) {a = a1; B = b1;} I Stream & operator> (istream & in, CEquation & c) {char ac, bc, xc, l; // ac = "+ /-", xc = "a-z symbol", bc = "="; cin> c. a> xc> ac> c. b> bc> l; // ax + B = 0 if (ac! = '+' & Ac! = '-') | Bc! = ') // The logic or "|" corresponds to "&" {if (xc <'A' | xc> 'Z' | l! = '0') cout <"format incorrect! ";} If (ac = '-') {c. B =-c. b;} c. s = xc; return in;} ostream & operator <(ostream & output, CEquation & c) {cout <c. a <c. s; if (c. b> 0) cout <"+"; cout <c. B <"= 0" <endl; return output;} double CEquation: solve () {double x; if (a = 0) {cout <"equation unsolvable" <endl; return 0 ;}x =-B/a; return x ;}char CEquation: getx () {return s ;} int main () {CEquation e; cout <"Enter the one-dimensional equation (input format: 3x-8 = 0/5 s + 18 = 0):"; cin> e; // In the two tests, enter 3x-8 = 0 and 5S + 18 = 0 cout <"equation:" <e; cout <"the solution of the equation is:" <e. getx () <"=" <e. solve () <endl; return 0 ;}