C and C++

Write a program to insert an element into an array at a given position

#include<iostream.h> #include<iomanip.h> class insertion { private: int n, m[100], ele, p; public: void getdata(); void insert(); void display(); }; void insertion::getdata() { cout<<“How many elements?”; cin>>n; cout<<“Enter the elements: “; for(int i=0; i<n; i++) cin>>m[i]; cout<<“Enter the element to be inserted:”; cin>>ele; cout<<“Enter the position (0 to “<<n<<“):”; cin>>p; } void insertion::insert() { if(p>n) { cout<<p<<“is an invalid position”; exit(0); } else { for(int i=n-1; i>=p; i–) m[i+1] = m[i]; m[p] = ele; n = n+1; cout<<ele<<” is successfully inserted”<<endl; } } void insertion::display() { cout<<“The array after the insertion is “; for(int i=0; i<n; i++) cout<<setw(4)<<m[i]; } void […]

Computer Graphics

Raster-Scan Display Processor

Figure shows one way to organize the components of a raster system that contains a separate display processor, sometimes referred to as a graphics controller or a display coprocessor. Scan conversion: A major task of the display processor is digitizing a picture definition given in an application program into a set of pixel values for […]

Computer Graphics

Cartesian reference frame

✓ Frame-buffer locations and the corresponding screen positions, are referenced in Cartesian coordinates. ✓ In an application (user) program, we use the commands within a graphics software package to set coordinate positions for displayed objects relative to the origin of the ✓ The coordinate origin is referenced at the lower-left corner of a screen display […]

Computer Graphics

Three- Dimensional Viewing Devices

Graphics monitors for the display of three-dimensional scenes have been devised using a technique that reflects a CRT image from a vibrating, flexible mirror As the varifocal mirror vibrates, it changes focal length. These vibrations are synchronized with the display of an object on a CRT so that each point on the object is reflected […]

Program for Bezier curve C and C++ Computer Graphics

Program for Bezier curve

/* Program to draw a Bezier Curve using graphics.h */ #include <graphics.h> #include <conio.h> #include <math.h> #include <stdio.h> void drawBezier(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) { double t; int x, y; for (t = 0.0; t <= 1.0; t += 0.001) { // Cubic Bezier […]

Program for 3D Rotation C and C++ Computer Graphics

Program for 3D Rotation

/* 3D Rotation of a Cube using graphics.h (BGI/WinBGI) */ #include <graphics.h> #include <conio.h> #include <math.h> #include <stdio.h> #define PI 3.14159265 // Projection function (simple perspective projection) void project(int x, int y, int z, int *px, int *py) { int d = 500; // distance from viewer *px = (x * d) / (z + […]