The difference between round C language and C++
Enter the radius to find the area;
C language
#include<stdio.h> struct MyCicle { double m_r; double m_s; }c1; intmain() { printf("Enter the radius of the c1 circle:"); scanf("%lf",&c1.m_r); printf("Output the area of c1 circle:%4.2lf",3.14*c1.m_r*c1.m_r); return 0; }
C++
#include<iostream> using namespace std; class MyCicle { public: double m_r;//The radius of the circle double m_s;//Area of the circle public: void setR(double r)//member function { m_r=r; } double getR()//member function { return m_r; } double getS() { m_s=3.14*m_r*m_r; return m_s; } }; // class abstraction // instantiate // find the area //Procedure-oriented is a function one by one //Object-oriented is a class one by one // class call execution process intmain() { MyCicle c1,c2,c3;//Define variable objects with classes double r; cout<<"Please enter the radius of the c1 circle: "; cin>>r; //Assign the attribute of the c1 circle c1.setR(r); cout<<"The area of the c1 element is: "<<c1.getS()<<endl; return 0; }
Better understanding of process-oriented and object-oriented