Computer Graphics

Graphics Functions

It provides users with a variety of functions for creating and manipulating pictures The basic building blocks for pictures are referred to as graphics output primitives Attributes are properties of the output primitives We can change the size, position, or orientation of an object using geometric transformations Modeling transformations, which are used to construct a […]

Computer Graphics

Define Computer Graphics & its applications

Computer graphics is an art of drawing pictures, lines, charts, etc. using computers with the help of programming. Computer graphics image is made up of number of pixels. Pixel is the smallest addressable graphical unit represented on the computer screen. Applications of Computer Graphics Graphs and Charts An early application for computer graphics is the […]

C and C++

C / C++ program to emulate the unix ln command

#include<stdio.h> #include<sys/types.h> #include<unistd.h> #include<string.h> int main(int argc, char * argv[]) { if(argc < 3 || argc > 4 || (argc == 4 && strcmp(argv[1],”-s”))) { printf(“Usage: ./a.out [-s] \n”); return 1; } if(argc == 4) { if((symlink(argv[2], argv[3])) == -1) printf(“Cannot create symbolic link\n”) ; else printf(“Symbolic link created\n”) ; } else { if((link(argv[1], argv[2])) […]

C and C++ Compiler Design

C/C++ program that outputs the contents of its Environment list

#include<stdio.h> int main(int argc, char* argv[ ]) { int i; char **ptr; extern char **environ; for( ptr = environ; *ptr != 0; ptr++ ) /*echo all env strings*/ printf(“%s\n”, *ptr); return 0; } OUTPUT SSH_AGENT_PID=3207 HOSTNAME=localhost.localdomain DESKTOP_STARTUP_ID= SHELL=/bin/bash TERM=xterm HISTSIZE=1000 KDE_NO_IPV6=1 GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2 WINDOWID=44040273 OLDPWD=/root/tan QTDIR= QTINC= USER= LS_COLORS=no=00:fi=00:di=00;34:l GNOME_KEYRING_SOCKET= SSH_AUTH_SOCK=/tmp/ssh-SEwJHJ3149/agent.3149 KDEDIR=/usr SESSION_MANAGER= MAIL=/var/spool/mail/root DESKTOP_SESSION=default PATH= […]

C and C++ Compiler Design

POSIX compliant program that prints the POSIX defined configuration options supported on any given system using feature test macros

#define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include<stdio.h> #include<unistd.h> int main() { #ifdef _POSIX_JOB_CONTROL printf(“System supports job control\n”); #else printf(“System does not support job control \n”); #endif #ifdef _POSIX_SAVED_IDS printf(“System supports saved set-UID and saved set-GID\n”); #else printf(“System does not support saved set-UID and saved set-GID \n”); #endif #ifdef _POSIX_CHOWN_RESTRICTED printf(“chown_restricted option is %d\n”, _POSIX_CHOWN_RESTRICTED); #else printf(“System […]

C and C++ Compiler Design

POSIX compliant program to check the following limits: (i) No. of clock ticks (ii) Max. no. of child processes (iii) Max. path length (iv) Max. no. of characters in a file name (v) Max. no. of open files/ process

#define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include<stdio.h> #include<unistd.h> int main() { int res; if((res = sysconf(_SC_OPEN_MAX)) == -1) perror(“sysconf”); else printf(“OPEN_MAX:%d\n”,res); if((res = pathconf(“/”, _PC_NAME_MAX)) == -1) perror(“pathconf”); else printf(“max_path name:%d\n”,res); if((res = sysconf(_SC_CLK_TCK))== -1) perror(“sysconf”); else printf(“clock ticks:%d\n”,res); if((res = sysconf (_SC_CHILD_MAX)) == -1) perror(“sysconf”); else printf(“max_childs:%d\n”,(res)); if((res = pathconf(“/”,_PC_PATH_MAX)) == -1) perror(“pathconf”); else printf(“max […]

C and C++ OS Shell Script

Program to count the number of characters words spaces and lines in a given input file

%{ #include int c=0,s=0,w=0, l=0; %} %% [ ] {s++;} [\n] {l++;} [^\t\n]+ {w++; c=c+yyleng;} %% main(int argc, char *argv[ ]) { FILE *fp; if(argc == 2) { fp = fopen(argv[1],”r”); if(!fp) { printf(“file doesnot exist\n”); exit(0); } yyin = fp; yylex(); printf(“number of spaces is %d\n”,s); printf(“number of character is %d\n”, c); printf(“number of […]

C and C++

C program that recreates a child process to read commands from the standard input and execute them

#include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> #include<wait.h> #define BUFF 20 int main() { char buff[BUFF]; int Pid = 0, i, ret, returnval; Pid = fork(); if(Pid == 0) { for(;;) { for(i=0; i<BUFF; i++) buff[i] = ‘\0’; write(STDOUT_FILENO, “SHELL>”, 6); read(STDIN_FILENO, buff, BUFF); if(strcmp(buff,”exit\n”) == 0) exit(100); ret = system(buff); printf(“exit status of the command = %d\n”, […]

C and C++ Data Structures

Find shortest paths to other vertices using Dijkra’s algorithm

What is Dijkstra’s Algorithm? Dijkstra’s Algorithm is a popular graph traversal technique used to find the shortest path between nodes in a weighted graph. Developed by Edsger W. Dijkstra in 1956, this algorithm is a cornerstone in fields like computer networks, GPS navigation, artificial intelligence, and routing protocols. Key Features of Dijkstra’s Algorithm Works on […]

Implement any scheme to find the optimal solution for the travelling salesman problem C and C++ Data Structures

Implement any scheme to find the optimal solution for the travelling salesman problem

Travelling Salesman Problem Using Nearest Neighbour Algorithm in C The Nearest Neighbour (NN) algorithm is a greedy heuristic method for solving the Travelling Salesman Problem (TSP). Though it doesn’t guarantee the optimal solution, it provides a quick and fairly efficient approximation, especially useful for large datasets where brute-force or dynamic programming becomes infeasible. /* Nearest […]