Procedure oriented programming basically consists of writing a list of instructions for the computer to follow, and organizing these instructions into groups known as functions. We normally use flowcharts to organize these actions and represent the flow of control from one action to another.In a multi-function program, many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data. Global data are more vulnerable to an inadvertent change by a function. In a large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure, we also need to revise all functions that access the data. This provides an opportunity for bugs to creep in.Another serious drawback with the procedural approach is that we do not model real world problems very well. This is because functions are action-oriented and do not really corresponding to the element of the problem.Some Characteristics exhibited by procedure-oriented programming are: • Emphasis is on doing things (algorithms). • Large programs are divided into smaller programs known as functions. • Most of the functions share global data. • Data move openly around the system from function to function. • Functions transform data from one form to another. • Employs top-down approach in program design.3. Write the Principles of Object-Oriented SystemsThe conceptual framework of object–oriented systems is based upon the object model. There are two categories of elements in an object-oriented system −Major Elements − By major, it is meant that if a model does not have any one of these elements, it ceases to be object oriented. The four major elements are −
1 2 3 4 5 6 7 8 9 10 11 12 13 | class HumanBeing{ public: HumanBeing(std::stringn):name(n){} virtual std::string getName() const{ return name; } private: std::string name; };
class Man: public HumanBeing{};
class Woman: public HumanBeing{}; |
1 2 3 4 5 6 7 8 9 10 11 12 | template <typename T> void xchg(T& x, T& y){ T t= x; x= y; y= t; }; int i= 10; int j= 20; Man huber; Man maier;
xchg(i,j); xchg(huber,maier); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | template <typename T, int N> class Array{ public: int getSize() const{ return N; } private: T elem[N]; };
Array<double,10> doubleArray; std::cout << doubleArray.getSize() << std::endl;
Array<Man,5> manArray; std::cout << manArray.getSize() << std::endl; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | std::vector<int> vec{1,2,3,4,5,6,7,8,9}; std::vector<std::string> str{"Programming","in","a","functional","style."};
std::transform(vec.begin(),vec.end(),vec.begin(), [](int i){ return i*i; }); // {1,4,9,16,25,36,49,64,81}
auto it= std::remove_if(vec.begin(),vec.end(), [](int i){ return ((i < 3) or (i > 8)) }); // {3,4,5,6,7,8} auto it2= std::remove_if(str.begin(),str.end(), [](string s){ return (std::lower(s[0])); }); // "Programming"
std::accumulate(vec.begin(),vec.end(),[](int a,int b){return a*b;}); // 362880 std::accumulate(str.begin(),str.end(), [](std::string a,std::string b){return a + ":"+ b;}); // "Programming:in:a:functional:style." |