Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
263 views
143 pages
CPU Part 2
nil
Uploaded by
Tejas Shastri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save CPU Part 2 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
263 views
143 pages
CPU Part 2
nil
Uploaded by
Tejas Shastri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save CPU Part 2 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save CPU Part 2 For Later
You are on page 1
/ 143
Search
Fullscreen
Solution of quadratic equation using pointer #include
#include
void main() { float a,b,c, root1,root2; void solve (float, float, float, float*, float*); printf("Enter a,b andc :"); scanf ("£8£%£", ga, &b, &c) ; solve(a,b,c, &root1, &root2) ; print? ("Alpha=#f\tBeta=$f\n" , root, root2) ; + petncdud ) . : fEevoid ma; void solve(float aa, float bb, float cc, float *ri, float #r2) he t : float delta; ‘dnt delta=bb*bb-4*aatcc; _ Beh *rls(-bb+sart (delta) ) /(2#aa) ; weet *r2=(-bb-sqrt (delta }/(2*aa) pray for Pointer and 1-p array #include
void main () { » p=65516,. 4 2 int arr[5]=(4, 2,843 p+0=65516 [Be ~~ — ; int tod p+1=65518 |B Pointer | p+2=65520 {7p #include +3=65522 ],4g Void mair p+4=65524 |: tint * (pel i *(pe2)e8 | ints * (p43) <3 ‘peary * (pra)ea ‘print for (3 for (i wn Reading and printing array elements using pointer #include
void main() { int *p,i; printf ("Enter 5 elements below\n") ; for(i=0; i<5; ++i) {scanf ("$a",p+i) ;} NICE, V.V.Nagar - Ph. (02692)238534print£("You Have Entered\n") ; for(iz0; i<5; ++i) Enter 5 elements below 145 0 -45 345 65 you Have Entered * 45 0-45 { printé ("d\n") *(pri))i pointer and character string #include
#include
void main () { char *s; int i; . > print é (*s=tu\n",s) 7 2 | . s="NICE Computer"; print£(“s=tu\n", 5); for(i=0; i
main() C struct a (char ch[7]; {struct a {char *str; struct a *ptr; di static struct a arr[]= iB { {"Niranjan*,arr+2},{"Parveen",arr), ("Ashish",arr+1) ye struct a *p[3]; . int i; for (i=0; i<=2; ++i)pli]=arr[i].ptr; : print£("\nts",p[0]=>str) ; printf ("\nts", (*p)->str) ; printf("\n%s", (**p)); } ICE, V.V.Nagar - Ph, (02692)238534Module 2.11 : File Management Writing a string (character by character) into a fils #include
Hnclude
void main() mt Enter a string : Hello How Are You (Contents of file CHAR. TXT would be . Hello How Are You) - FILE *fp; int i; char str[80]; printf£("Enter a string : scanf("%[*\n]", str) ; fp=fopen ("CHAR. TXT", "w") ; for (i=0; i
#include
_ #include
void main() { FILE *fp; +» char ch; fp=fopen ( "CHAR. while ( (ch= Hgete( Ef raw i) ([owette oe “Bednto a £411 ‘J. From the £: ', Separate even and odd numbers and. store them into files -UXT and ODD. TXT respectively. Display contents fall the three files. es #include
10 « Enter 10 numbers 12345678910 Contents of File ALL. TXT. 12345678910 Contents of File EVEN. TXT 246810 , Contents of File ODD.5XxT. while ( (num=getw(#£1)) !=EOP) print£ ("d\¢i"? niin) ; fclose(f£1); printf£("\nContents of File EVEN. £2=fopen("EVEN. TXT", "r") ; while ( (num=getw (£2) ) != Eclose (£2) ; f print£(*"\nContents of Fi £3=fopen(*ODD.TXT", "x" while ( (rumegetw(t3)) Eclose(£3) ; Read n nunber from keyboa: all the contents of UNSOR Display Cor tinal #inclh oni void main ( dint n,i;data,arr [10]; FILE *£1, *£23 printf ("How scanf ("$d", ni) ; printf ("Enter %d numbers\n") ; £2=fopen ("UNSORT. TXT", "w") ; for(i=0; icn; ++4) numbers ? "); { scanf("%d",&arr (iJ); putw(arr(i},£1); } fclose (£1); £1=fopen ("UNSORT. TAI", "x") 7 i=0; NICE, V.V.Nagar - Ph. (02692)238534 sand store into SORT.TxT. les. How many.-: Enter 4 numbers 12-40 156° Sorted Numbers From File -40 12 156 fol ££ forwhile( (data=getw(£1)) !=EOF) {arr [i++]=data;} felose(£1) ; nei; . for (i=0; i
arr[j]) ae {temp=arr [i] ;arr[i]=arr[j]:arr[j]=temp;}" ) me ‘ } . : £2=fopen ("SORT.TXT", "w") 7 : a for (i=0; icnum; ++i)putw(arr [i] £2); tne Eclose (£2) ; print£ ("Sorted Numbers From File\n"); 2. ges £2=fopen("SORT.TXE","x") ; ae Me gn" ta)ig
void main () { . FILE *f£; - int total, i,rol} float epi; — | char name[29] printe£ ( Rollno : 11 Name s Shasbikant CPr's 7,800000 Rodino 172 Names Ashok CPL’; 6.900000 ollno : 33 Mana + Uanati CPT + 9.300000 print£ ("CPI %a scant ("8£", &cpi) vet fprintf (£,"%4d%20s%5.2£" ,vollno, name,.cpi) 7's : scloge(#); a f=fopen ("student .txt","r"); * for(i=0; ictotal; ++i) + {Escanf (£,"$4d820s%5.2£", &rol1no, name, &cpi) ; printf£(*Rollno : $d\tName : %s\tCPI : #f\n",rolIno,name,cpi) ; } ek fclose(f) ; os } — woe, oh 135 NICE, V.V.Nagar - Ph. (02692)238534Random Access To File 4 Assume that CHAR.TXT file already exists and it contains a lin "Hello How Are You". #include
void main() ( FILE *fp; int n; char ch; fp=fopen("CHAR.TXT", "r"); n=ftell (fp); printf£("%d\n",n); ch=getc(fp); printf("%c\n",ch); chegetc(fp); print£("tc\n",ch); BOQpo Temes fseek(£p, 7,0); prin neftell (fp); printé("$A\n",n) ; felo ch=gete (fp); printf ("%c\n",ch) ; a fseek(fp,-5,2)7 os n=ftell (fp); print£("%d\n",n eS UBB Two file ch=getc(fp); printf ("%c\n" ,¢h: ;, Generate rewind (fp) ; 4 UB two file: ‘n=ftell (fp); print£(*%d\ : 4 fi #include ch=getc(fp) ; print£ ("sq i * MB void mais { ToT 77 aT TTT int Command Line Argument bint File Name : CM.CPPS , Bs \Material\C\File>cml hello | # FILE #include
void main(int argc, char*argv{]) {FILE *fp; _char ch; fp=fopen{argv[1],"r"); while ((ch=getc(fp)) !=EOF) . ) frinté("8e", ch) 3) ICE, V.V.Nagar - Ph. (02692)238534B.command Line Argument . : ‘File Name : MYCOPY.CPP ‘ Usage : mycopy source destination ay Hnclude
} void main(int argc, char*argv(]) : { FILS *£pl, *£p2; char ch; fpl=fopen(argv(1],"r") i~ £p2=£open (argv[2], "w") + while((ch=getc(fp1) ) !=EOF) : {pute (ch, fp2); . eo } SE printf ("My Message : 1 File Copied"); Ly fclose(fpl); : fclose(fp2); Datal and Data2 contad, re i z mee. Ee e ‘List of these “two files. #include
void main() { int a[100],b[100 FILE *fpl, *£p2) *£} cere a re m=getw (£p2 isles yates) fclose (fp2)7) /* Merging 4 ; iem; ++i) cLil=alil; for(i=0; i
el3]) {temp=c [i]; elil=cl3]+ : gisi-temp; . : NICE, V.V.Nagar - Ph. (02692)238534 137,/* Writing back into the third filet/ £p3=fopen ("DATA3", "w"); : for(i=0; i
void main(int argc, char *argv[]) a { FILE *fp; char ch; int line=0,totalchar=0; fp=fopen(argv(1],"r"); while ((ch=getc(fp)) !=EOF) { Pe if(chs='\n')liner+; °°) else totalchar++; printf ("Total number of: print£ ("Total ni Passing standard is 40 marks in each subject. #include
[output \ - #define total 500 Self struct student { char name [20]; int m1,m2; he void main() . { L FILE *in, *out; int i; student s (500); NICE, V.V.Nagar - Ph, (02692)208534char result [20]; in=fopen("input", "x"); out=fopen("output", "w"); for(i=0; i
=40 && s[i] .m2>=20)strepy (result, "PASS" ao else strepy(result, “FAIL") ; fprint£ (out, "%20s%3dt3d%3dt4a\n", . s[i].name,s[i].m1,s[i] .m2,s[i] .ml+s[i] .m2, result); } fclose(in); fclose(out) ; 7. A file DATA is having 500 integer numb , DATA file and creates two more fil contain all the numbers arrange respectively. Program should also display tl #include
#define total 500 void main() {FILE *dt, *as, *ds;* int num[total], £4 dt=fopen ( DATA» } for (is0; ictotal; ++i)putw(num[i),as) + for (istotal-1; i>=0; --i)putw(num[i] ,ds) ; fclose (dt) ; fclose (as) ; fclose (ds); printf ("Descending Printing\n") ; ds=fopen("DES", "r") ; aa while ((temp=getw(ds))!=EOF)printé("td\n",temp); >" fclose (ds) ; ~ ‘ “) NICE, V.V.Nagar - Ph, (02692)238534Module 2.12 Dynamic Memory Allocation & Preprocessor Dynamic Memory Allocation To understand DMA, let us first understand static memory alloca- tion. Array is an example of static memory allocation. Fox example, if we write int num[100], compiler will allocate total 200 (100 x 2)] bytes for the array. Now if our program uses all 100:elements (200; Bytes) the memory utilization is considered as 100% (No ‘memory wast~' age). But if we use less than 100 elements than other memory. “Loca=! tions will be wastage, Here the problem is, we do not know in advance, i.e. before running the program, that how much memory we will be. needing. So we have to give some maximum figure (here 100). But if we could allocate memory as and when required, i.e. at run time, not before running the program, we can Yeduce or eliminate the wastage memory problem. The process of allocating memory at run-time’ is known as dynamic memory allocation. There are four “memory manage-. ment functions” that can be used to allgcat ‘and’ frée a memory during program execution. ted size of bytes and returns a . pointer to the first byte to the allocated block. ‘The mali size weatttumns a pointer to type void. This means we can j Pek assign it to any type of pointer. Example: int *x; “x= (int*), malloc (100 * sizeof (int)); re Above statement, reserves a block of 200 bytes (100. x 2) and: address of of the first byte is assigned to x which is pointer to integer type quantity. ealloc: Allocating multiple blocks of memory. While malloc function reserves single block of menory of ; specified size, calloc allocates multiple blocks of storage, each of; NICE, V.V.Nagar - Ph. (02692)238534same size, and then sets all bytes to zero. . ptr = (cast-type*) calloc(n,byte-size) free: Releasing the used space . With the dynamic run-time allocation, it is our résponsibility to release the space when it is not required. The release of storage space becomes important when the storage is limited..The syntax of free function is : free (ptr); where ptr is a pointer to a memory block which has already been created by malléc and calloc. . realloc: Altering the size of a block If we want to change the size of already allocated blot. this function is used. The format is ptr = realloc(ptr,new-size) Concepts of Linked List: . A list is a set of items organized s entially. an warray is an ‘example of list. In array we use index fOr. manipulating individual elements. one problem in: ave.to define the initial size of the array i roblem is we cannot increase or reduce the: sf é é in-time. A completely different -we nie ae E item is a list part of struct structure containing next i: called linked list because it 4: from one item to next. Structure 1 Structure 4 Next jee > Each structure? ode and consists of two fields, one containing:the item and other containing the address of the next ” item. Adinked 1. erefore a collection of structures ordexed not by ther e physical Pl cement in memory (like an’ array) but by logical links. that are’stored as part of data in the structuré. itself. Example of Linked*List . |. finclude
struct node { ot int item; . ane node *link; Ve void main() - . Item NICE, V.V.Nagar - Ph. (02692)238534 ° ae)node *first, *temp, *prev; temp= (node*)malloc (sizeof (node) ) ; tenp->item=10; : . temp= (node*) malloc (sizeof (node) ) ; temp->item=20; prev->link=temp; Prev=temp; temp= (node*) malloc (sizeof (node) ) ; temp->item=30; prev->link=temp; temp->1ink=NULL; temp=first; while (temp! =NULL) { printf (“%d\n",temp->item) ; temp=temp->link; } } oureur 10 20 30 Types of Linked List (a) Linear List tem NICE, V.V.Nagar - Ph, (02692)238534Application of Linked List: pete Linked list concepts are useful to model many different abstract data types such as queues, stacks and trees. Bs at other end. This obeys the discipline of “First In First Out” ~ FIFO. Example: Row for ticket at cinema. = Stack is a list where insertion and deletion is made al only. This obeys the discipline of “Last In First “out* “"LIFO, Sxample: A Pile of Books. Normally, insertion in stack is known as PUSH and deletion from stack is known as POP, Lt : ree is a two-dimensional linked list. Trees “dre ‘frequently encountered in everyday life. Example: The organization chart of a large company. . Fock ba Preprocessor : . The preprocessor, as its name implie: esses the source code before it passed Operates under the control of what is line or prepreocessor directives:,,The placed in a program before the si passes through the compiler, sii ‘any preprocessor directives {Tf per the directives) are take over to the compiler. 2 ve £15 program that’proe- hréugh the ‘compiler. It prOcessor command cessor directives are ‘ore the source code reprocesso for Preprocessor 2) Source Program after proces . sing Proprocessor directives define #include #endift Queue is a list where insertion is made at one-end and deletion’‘The preprocessor directives can be divided into three categories 1, Macro Substitution directives. ©” a. Simple Macro Subtitution b. Macros with argument c. Nesting of macros 2. File Inclusion directives. 3. Compiler control directives. 1, Macro Substitution directives. ore Macro substitution is a process where an identifier ina aprogram iis replaced by a predefined string composed of one or-more: tokens: a. Simple Macro Subtitution ‘ Examples are: #defineCOUNT 100 #define TRUE 1 #define PI 3.1415 #define CAPITAL “DELHI” In above macro definitions, their equivalent contants val If we have macro definition #deifne D 45-22 and #defin A would result irito 45 -22, But if we write the macy #deifine D (45-22) and < defined name ocgirs. include 7 oureor: x is gr ’b. Macros with argument , Refer following program to understand macros with arguments. ae #include
#define CUBEL (x) (x#x*x)- #define CUBE2 (x) ( (x) * (x) * (x)) #define MAX(a,b) ( ((a)>(b)) ? (a) : (b) ) #define MIN(a,b) ( ((a)<(b)) ? (a) + (b) ) ‘void main() {int a=5,b=10; print£(*Sa\tea\t", CUBE1 (a) , CUBE2 (a) My i printé (“%a\t%d\t" , CUBE1 (a+b) ; CUBE2 (a+b) ) + printé (“%d\t%d" ,MAX (a,b) ,MIN(a,b))7 NICE, V.V.Nagar - Ph, (02692)238534} - of oureuT soeeM testy os! 125 125 115 337510 5 avidoet it sual ¢. Nesting of macros is.ai Baipsxalh ort bos avn #include
#define SQUARE (x)..( (x) * (x) ) 2 #define CUBE(x) : (SQUARE(x) * (Gx) ) Lay ado #define SIXTH(x) (CUBE (x) *CUBE (x)) #tdefine MAX(a,b) ( ((a)>(b)) ? (a) #define MIN(a,b) ( (a)s{>)) ? (a) pat vo void main() dt sil’! gow Jor (b) ) (bibs ovispexid 10 ib yorxe# sat s+ {int a=2, b=! 10,c=8; , s printf (*\n8d\ted\t%d" , SQUARE (a) , CUBE (a)»SIXTH(a})idzoso print (*\tmax=d\ tmin=%d” , MAX (MAX (a, b)',¢), MIN (MIN(a,,b) ene } OUTPUT hip 4 8 64 max=10 mi . 4. wile mclusion directives. | / Sneed not rewrite! \ thespreprio deniers i “The difference Petyeen £4 ©) of First, declaration; be se “the specified: file 3 er di: the in the standard sdirectoryii {e.g._.Cz\EC\ING only. in the stat | cont: _
main() (#define combine (x,y) x##y o int total=10,sales=20, totalsales=1000; printf (%d", combine (total, sales) ) ; NICE, V.V.Nagar - Ph. (02692)238534| NICE, VV. Nagar - Ph. (02692)238534Module 3.1 - Decision Making and Branching 4. Write a program to determine whether a number Is ‘odd’ or 'even' and print ti message NUMBER |S EVEN or NUMBER IS ODD (a) without using else ojstio) Y and (b) with using else option. 5 /* (a) Without Using else option */ #include
main () { int nun; printf("Enter your number : "); scant ("$d", &num) ; Lf (num2==0)print£ ("NUMBER IS EVEN") ; if (num&21=0)print£ ("NUMBER IS ODD") ; } /*(b) With Using else option */ #include
main() { int num; printé ("Enter your number : "). scanf("$d", enum) ; " - if (num2==0) printf ("NUMBER IS EVEN") ; * else printf ("NUMBER IS QDD' ‘ } is 2... Write a program to. if (auinc=200) goto again; printf ("SUM=%d", sum) ; } c * “3 . 3. Aset of two linear equation with two unknowns x1 and x2 is given as: ax1 + bx2 =m and cx1 + dx2 =n. The set has unique solution x1=(md-bn)ad-cb) and x2=(na-me)/(ad-cb) provided the denominator ad-cbiis not equal to zero. Write a program that will read the values of constants a, b, q d, mand n and computes the value of x1 and x2. An appropriate: message st Should be printed if ad-cb=0. #include
€ main () : « {int a,b,c,d,m,n,x1, x2; 4 “ ( NICE, V.V.Nagar - Ph, (02692)238534brint£ ("Enter a,b,c,d,mn =>"); +o pSeant (* 8dadSdkdedea", ga, Sb, ac, xd, &m, én) ; Spe ee if ( (a*d-c*b) ==0) (print ("Denominator becomes zero") ;) ap ise (x1 = (m*d-b*n) /(a*a-c#py ; . Fo, ¥2 = (n*a-m*c) /(a*d-c*b) ; on i printf ("X1=%d\nx2=84",x1,x2) ; nee} ) : ) aa . 4 Given alist of marks ranging from 0 to 100, write a Program to compu print the number of students: CBR a . (2) who have obtained more than 80 marks, an : (b) who have obtained more than 60 marks, ae : (c) who have obtained more than 40 marks, Na ts (d) who have obtained 40 or less marks, * (e) in the range 81 to 100, (fin the range 61 to 80, (g) in the range 41 to 60, and +. (h)inthe Tange 0 to 40, ~ 4 The program should use. minimum fumbe: f ifs: #include
nain() { int total_student ,more80=0, int bet81to100=0, bet61togo. int marks; 3 printf ("Enter totalsnuttber of students” scanf ("$d" , &total_ student. again: ee : iore60++;more40++;betBitol004+;) ° *y 1 S<= 80) {more60++;mored0++; bet 61to804. : 'S540&émarks<=60) {mored0++;betalto60e+7} 0) | else(less40++;bet0t040++; } : , pefetal_student--) oe if (total student>0)goto again; of Peinté ("\nstudents who have obtained more than 80 marks ; | printf ("\nStudents who have obtained more than 60 marks. vg Brinté("\nStudents who have obtained more than 40 marks, : 84", mored| ‘printf ("\nstudents who have obtained less than 40 marks ", Less4( printf ("\nstudents in range 81 te 100 marks : $d", bet81to100) : wprint£ ("\nstudents in range 61 to 80 marks : 8d", bet61t0g9) printf ("\nstudents in range 41 to 60 marks. ; 8d", bet 41t06( ) brint£("\nStudents in range 0 to 40 marks : $d", bet0to40);., $d" ;more6| s ; 5. Admission toa Professional course is ‘subject to the following conditions:. - (a) Marks in mathematics >= 60 . {b) Marks in physics >= 50 poe va (c) Marks in chemistry >= 49 ' ay (d) Total in all three Subject >= 200 or Total in mathematics and physics >= 18 +8 1B NICE, V.V.Nagar- Ph. (02692)238534 146tion to list the eligible candidates. #include
main(). ¢ int total_student,m,p,c; printé ("How many candidates ? "); scanf ("%d", &total_student) ; again: print£("Enter marks in physics,chemestry & maths +"); scanf ("sd%d%d", &p,&C, 1m) ; fat Lf (m>=6084p>=50&6.0>=4086 (m+p+e>=200 | |m+p>=150) ) ’ - printf ("\nCandidate is eligible"); ~ i . else print£("\nCandidate is not eligible" total_student--; if (total_student>0) goto again; } 4 6. Write a program to print two dimensional squi root of any number from 0to9.9. #include
#include
main() { float x=0.0,y=0.0; label2: printf ("\n"); y=0.07 labell: printf ("85.2£) yey+0.1; 3 } : 7 Shown below isia Floyd's triangle - 23 we 456 zeus <.78910 . (aw Write a progra te print this triangle. (b) Modify the program to produce the following form of Floyd's walle » * > findhnae’
qain( ) ~ Ly int num=1, totall=1,total2=1; * label2: NICE, V.V.Nagar - Ph, (02692)298534totali=1; printé("\n"); labeli: if(totali<=total2) ( printf ("%3d",num++) ; if (num>91) goto end; totall++; goto label; } total2i+; goto label2; end: i (* (b) */ #include
main() dn num=1,total1=1, total2=1; label2 : totali=1; : printf ("\n"); num=total2; labell: if(totali
main () { dnt mp, hp; float md, hd; Purchase Item Discount 0-100 Mill Cloth 101-200 5% 201-300 7.5% } 8 Acloth Showroom has announced the following seasonal discount on. pur- Handlopm Items 7.5% yl 10.0% 10.0% 15.0% Write a program using switch and If ‘statement to compute the net amount to be paid NICE, V.V.Nagar - Ph, (02692)238534 . .printf ("Enter mill clothes purchase : scanf ("td", &mp) ; printf ("Enter handloom clothers purchase : "); scant ("%d", &hp) ; “Vi switch (mp/100) int {case 0: Ee caso 1: s00)mi=0; h @ else ma=5.0; main () break; : case 2: if (mp==200)md=5.0; else md=7.5; int case 3: default: ) switch (hp/100) {case 0: case 1: case 2: (a) nested if statement (b) else if statements and ¢ conditionalo erator Pp 7 (a) */ re #include
nu main() } { ‘printf int x,y; — printé ("Enter x: "); scant ("d" , &) ; if 000) NICE, V.V\Nagar - Ph, (02692)238534100) })z : function 152 (iE (x= else y=1i d else y=-1; . printé ("Y=8",y); : : * ) 7* (b) */ #include
main() { ! int x.y7 printf("Enter x: ")7 scanf ("%d" , &x) 7 print£("Y=%d",y)7 } i (oe) #7 #include
main() ¢ int x,y; printf ("Enter x + scanf ("%a", &) 7 . It “Decision making and looping 4. Given.a number write.a program using while loop to reverse the digits of ‘For example, ‘the number 42345 should be written as 54321. long num, rev_num=07 printf ("Enter Number : "); . scanf("81d",S:um); while (nun>0) {rev_num*=10; vev_num+snum’10; num/=10; } printf ("Reverse Number : 1d", rev_num); } NICE, V.V.Nagar - Ph. (02692)2385342. The factorial of an integer m is the product of consecutive integers from 1 t That is, Factorial m = ml = m x (m-1) x (m-2) K 2 X 1. . q Write a program to compute and prints a table of factorials for any given m| #include
4 main() { int i,m; long fact=1; print£("Enter m: "); 1 scan£ ("%a" , &m) 7 for(is2; i
main() int num, sum=0; printf ("Enter any number : "); scanf ("%d" ,&num) ; while (num>0) {sum+=numt10; : num/=10; aly } 5 Ea oe print£ ("Sum of the digits is $d\n%,sum); } 4 The number in the sequence’ 123581321....are called Fibonacei numb Write a program using a do-while loop to calculate and print the first m Fibonaj numbers,“ #include
.” main()) fo { es ? int n=0,m=1,temp,total; ~~ printf ("How marly numbers : "); ; scanf ("%d", &total) ; : while (total>0) {printé("%d\t";m); temp=n; n=m; memttemp; fotal="7 } 5. Write a program to evaluate the investment equation V = P(1+r)" and print the tables which would give the value of V for various combinati the follcwing values of P,r and n. P: 1000, 2000, 3000,......-, 10,1000 r:0.10, 0.11, 0.12,...-.,020 Nit, 208, veers 910 NICE, V.V.Nagar - Ph. (02692)238534MB include
gaint) ait . Pong P, V=0, temp_P; : int n; {float x; for(P=1000; P<=10000; P+=1000) » (V=05 temp_P=P; ~ for (r=0.1; r<=0.2; r+=0.01) {V=0; P=temp_P; : printf ("Amount=1d\tRate=%f\n\nYear\t\tMoney Value\n",P,r); for (n=1; n<=10; ++n) . {V=P*(1+r}; * printé ("Sd\t\t%ld\n" nV) P2V; : ) — } 6 Write a program to print the following outputs using for loops. (b) © : I rere 1 22 teen 22 333 wee Pry may #7 finclude
int) int i,j, space; for(i=5; i>0; --i) { _ NICE, V.V.Nagar - Ph. (02692)238534for (space=1; space<=(S-i); ++space) {printf£(" "))} for (j=i; j>=0; --J) {printf ("*");} printf ("\n"); ) * (ce) */ include
ain() nt i,j,space; or(i=1; i<=5; ++i) include
ain() nt count=0,i,age; “ int ALS or (i=0; i<100; ++i) for(ix0 | fok printé ("Enter age f¢ son #%G: ",i1); , scanf("$d" gage) ; SNe } x 50.age>60) continue. * 2 We : : rintf ("Number of desired'person = %d", count); ¢ nm Write a program to print a table of values of the function y=exp(-x) for x Vani inci from 0.0 and 16.0.. “AR nain() include
: { include
pint. i,t ain() int Sur int sur loat x,y,57 gepcintt nt count=1; AB scant ( rint£("\n "); WR for (i= ox(j=0; j<10; ++j)printé(*------- "G { rinté("\n"); . pr or (x=0; x<=10; x+=0.1) i 86 st { if (x==0)printf(" x") else if (x<=0.9] | (count-1)%1 ICE, V.V.Nagar - Ph. (02692)238534 )print£("87.2£",x);else printf ("%7.2£*,exp(-x)); if(count==10) . & { printf£("\n "); . for(j=0; j<10; ++j) print £(*"------- "Ge y if(count%10==0)print£("\n") ; count++; } . printf£(" "); for(j=0; j<10; ++j)printg(*------- "e printé("\n"); } Module 3.3 - Arrays 1. Write a segment of a program that initializes the array A as follows. . 10000 See 01000 00100 00010 me 00001 . . * All diagonal elements are initialized to one an #include
$ main() C int A[5][5],i,3; for(i=0; i<5; +44) ) else A(1] (j]=0; 2. Write a program for fitting a straight line through a set of points(xi,yi), i=1 .. .n. The straight line equation is y=mx+c. and the values of m and c aré given by m= (nExy, * (Zx)(Zy))MA(Ex4)-( Ex,)?) , c=t/n (Zy,-mzx) All summations are from 1 to n. #include
: inl ) x varying int i,n,x[10],y{10],m,c; int sum_xy=0, Sum_xSum_y=0,Sum_x=0, Sum_y=0; int Sum_xSquare=0; printf ("How many points : "); scant ("$d",&n) ; for(i=l; ix=n; ++i) ' ( printf ("Enter (x%d,y%d) scanf ("sdtd", &x(i},&y[il); “Sum_x+=x [i] ;Sum_y+=y [i]; Laid; 156 NICE, V.V.Nagar - Ph. (02692)298534 157oe nena paneer nen Sum_xyt=x[i]*y(i)7 Sum_xSquare+=x(i]**[i]; } : mms ( (n*Sum_xy) ~ (Sum x*Sumy) ) / ( (n*Sum_xSquare) ~ (Sum_x* Sum) ) i c= (Sum_y-m*Sum_x) /ni printf ("m=%d,c=%d",m,c) 7 } . 3. The daily maximum temperatures recorded in 10 cities during the month of - January (for all 31 days) have been tabulated, Write a program to read the table jonal array temperature, and to find the city and day elements into a two-dimensi corresponding to (a) the highest temperature and (b) the lowest ‘temperature.’ #include
main() float temp[31] [10] pmax=-999.99,min=999 .99; int i,j,max_day ,max_city,min_day,min_city;; for(i=0; i<31; ++i) { 2 for (j=0; j<10; +45) 2 2 & brine? (*Day:8d City:td Temp 7 ",i+1,5 scanf ("td8d", &temp Ae “ if (temp [i] [j] >max) i£(temp(i] (j]
=1&&vote<=5) count [vote=1] ++7 for(i else spoilt++; { print£ ("More Voters ? (y/n) ")i 5 choice=getche (); _#F y 2 for (is0; i<5; ++4) : NICE a ______. NICE, V.V.Nagar - Ph. (02692)238534ith of he table and day rature. a} } city); city); d1to5 2aper. ndidate e1tod, ald also 158 { print£("\ncandidate %d gets %d votes", i+1, count [i]); } . * printf ("\nThere are $d spoint ballots",spoilt); } 6. yhe following set of numbers is popularly known as Pascal's triangle. it 121 1331 14641 Write a program to calculate the elements of the Pascal triangle for 10 rows printresults. #include
pain ) int p[10](10],i,3; for (i=0;i<10; ++i) { print£("\n"); for (j=0;j<=i;++3) C 0} li==j) pli] (J]=1; else p[i] [j]=pli-1] [5-1] +pli-11 [5 Write a program to read the data and determine the following. (a) Total marks obtained by each student. (b) The highest marks in each subject and the Roll no. of the student who secured it. . (c) The student who obtained the highest total marks. #define ALL 4 #include
main() int marks [ALL] (3]',i,j,student_total [ALL] ; int High Marks [3]={0,0,0),High Rolino([3] ,High_total=0,High_total_Rollr for(i=0; i
High Marks [j]) ({High_Marks (j]=marks [i] [3];High_Rollno[j)=i+1;} if (student_total[i]>High_total) {High_total=student_total [i] ;High_total_Rollno=i+1;} orintf("\n\nTotal marks obtained by each students"); for (i=0; i
ain() nt c[{total*2],a[total] nt 1,i=0,5-0,k; d if(j==5) {for(1=i; l
define n 3 . main () { int a(n] {n} ,b{n] (n] ,cla] [nl ,4,5,/k; print£ ("Enter td x $d matrix A\n",n,n); for(i=0; i
Module 3.4 - Handling of Character Strings 1. Write a‘program which.teads your name from the keyboard and outputs a list of ASCII codes which represents your name. mo finclude
a rain() print£ ("Enter your name : "); : Ascanf ("%s" name) ; : for (i=0; name [i] !="\0';++i)printé ("te=%d\n" name [i] ,name[i]); | } 2 Write a program to do the following . : (a) To output the question "Who is the inventor of C2" oat _ «(b) To accept an answer . is ee (c) To print out "Good" and then stop, if answer is correct. (d) To output the message "try again’, if the answer Is wrong. (e) To display the correct answer when the answer is wrong even at third at- alti- - (02692)238534 Bee ~~ 161#include
* #include
main() ‘BB scan { . 9B prin char name [30], true_name[30]="Dennis Ritchie"; BB scan int i : for(i=0; <3; ++4) { ~ print£(*\nWho is the inventor of ¢?"); seanf("%[*\n]",name) ; if(strcmpi (name, "Dennis Ritchie")==0) { print£("Good\n"); return 0; ) else print e( “Try Again\n"); fflush (stdin) ; } } string. Assume that mcharact #include
#include
main() { char str [80]; print # ("Enter:starting igcation i"); scant (*%d", &m) o3 erintt ( Characters : "); prints seanf ("Sd",én); 1£(((m+n)>strlen(str)) | |m>strlen(str) | Inostrlen (str) I Im<01 In<0) re printf("Error : Input parameter out of range 11"); _ ON return 0; inclu } in() cor(ism; i<=min; ++i)print£("%e",str[i]); tinclude
tain() char str[80],word[20],extract [20]; ICE, V.V.Nagar - Ph. (02692)238534int i, j,count=0; print£("Enter a string : "); scanf ("%[*\n}", str); printf ("Enter a word : scanf ("%s", word) ; for(i=0; i
7 : main() { char str [80], temp; int i,d;. printf ("Enter a string : scant ("%s", str); . Z for(i=0; i
. main() : { L char str[80]="NICE produces fluent ¢ programmers"; . char newword[20}="C", oldword[20]="COMPUTER", extract (201; char dummy [80}="\0"; int i,j,count=0,k; for(i=0; i
. } int’ x,y; Float main() fl c if void exchage (void) ; el printf ("Enter x andy: "); scanf ("$d%d", &x, 6y) + print£("\nBefore calling fun . exchage(); ° s : prince (* \nafter calling funct $d y=$d\n", x,y); } int fa oid exchage (void) / C int temp; : in temp=x; fo xEY? xe ystemp; | } } “ 4 Ww pl or ro #include
|. include
{ float sum=0,x, £ (float, int); int fact (int); printf("Enter x : scant ("%£", &&); print# ("How many terms ? "); scanf(" ter, ani . Sumt=t (x, peinee (vane %£", sum) ; "he ee float f(float x,int m) { float temp=pow(x, 2*m-1) /fact ( if(m-=n) {return (temp) ;} else if (m821=0) return(temp - f return (temp + £{ ) int fact (int m) C int i,ans=1; for (i=2; icon? nda floating-point value to an indicated decimal ber 34.557 would yield the value 34.56 when itis rounded off! two decimal places. #include
=0.5)new_num++; S return( (float) (nmew_num) / (float) (powér.(10. } . 5. Write a function prime that return: turn 0 otherwise. #include
main() { int prime (int) ,num; printé ("Enter a numb scanf ("$d", &num) ; if (prime (num) =: {printf ("Number %d is. else int prime(int { int i; con for (i=2; i<(n/2); ++i) : pris (i (n8is=0) return 0; “4 scat } : : ‘ priz return 1; scar 3 . prir 6. Write a function that will scan a character string passed as an argument and. Scar convert all lower-case characters Into Upper-case equivalents, ; pra #include
8 scar #include
prir #include
. . ° nain() NICE, V.V.Nagar - Ph. (02692)238534pchar str [80]; tYoid convert_upper (char s[80}); forint f ("Enter a string : "); " ae uae gcanf (*[*\n]",str); + Noah tog Wwert_upper (str) ; ~ tee forint £ ("\nts",str) ; roid convert_upper (char s[80}) or (10; icstrlen(s); +44) if (islower (s[i]))s[i]=toupper(s[i}) 7, Module 3.6 - Structures sn Unions. Define a structure that describes a hotel. It shou! , the name, address, grade, average room “Write a function to perform the following qi (a) To print out all hotels of a given grade in {b) To print out hotels with room charges | finclude
struct hotel { char name [50]; char address [100] ; char grade; float avg_room_chargé int total_rooms; ; si float chargé} char g? for(i=0; i
t «for (j= id spor (1=0; i £15 Below specified charge are\n"); Seine : printf printé print, prints ? y @ print, cE (" \nN 1 2s ) one ntf ("\nName™ 8s", x.name) ; men’ nef ("\nAddress_ 2s", x.address) ; pats ae NE ntf("\nGrade +*. grade) ; include
* lude
ict cricket y Write at E, V.V.Nagar - Ph. (02692)238534 uy[struct cricket player[50], dummy; int 1,3; prints ("Player # d\n", i+1); an printf (“Name : "); seen - scanf ("%[*\n]",player [i] .p_name) ; i printf ("Team Name : "); . - scanf ("%[*\n]",player[i] .t_name) ; . printf ("Batting Average : "); grant ("8£", splayer[i] .b_avg); for (i=0; i<49; ++i) for (j=itl; 3<50; +43) if (strempi (player {i] ¢ : for(i=0; i<50; +41) : why. Module 3.7 - Pointers Bees Write a program using pointers to read in an array of integers and printits elements in reverse order. e “ fidefine N 5 : Wtinclude
ain() printf ("Enter %d elements below\n",N); Gfor(i=0; i
=0; ~-i)print£("$d\n",* (A+i)); Write a function to calculate roots of quadratic equation (ax? + bx'+. ¢=0). The function must use two pointer parameters, one to receive the coefficients a, b ICE, V.V.Nagar - Ph, (02692)238534 OSand ¢ and the other to send the roots to the calling function. The roots are given by following equation : X= (-b + Square root(b?- 4ac)) /2a #include
#include
/main() ’ { ” £loat *para, *root; . void find_root (float*, float*) ; . printf("Enter a,b,c : "); “ scanf ("£%f£%f" ,para,para+1,para+2) ; find_root (para, root) ; . print £ ("\nRoot1=%f\nRoot2=%£\n", *root,, *root+1) ; } void £ind_xoot (float *p, float *r) L float délta=(* (p+1)) *(#(p+1))~ (4* (p) * *rs(~ (*p+1) +sqrt (delta) ) /(2*(*p) ) 4, * (x41) =(- (*p4l) -sart (delta)) / (2*( #5) } 3. Write a function that receives ‘sorted array of inte and inserts the value it its Spfrect { placa. : #include
#define N 5 main() { int *a,num, i; . int “insert (int*, int) ;; “ ) printf ("inter all $d elements below in ascending sorted order\n" ,N)j fyold ade for (i=0; i
#define N 3 4 main’) Pint *a[3],*b[3],*c13] 4,57 Mae i Avoid add(int*[],int*(],int*{]); printf ("Enter tdxtd matrix A\n",N,N); for (i=0; i
for(j=0; 3
nain() ( thar *day_name(int) ; ‘responding day. The day nai Jocal to the funtion. int arr[n 4E( (X=by . prin rint£ ("%s",day_name(4)); jelse * "pri } ‘Bint b_sez { int first a2: Ih ig (firsts aon Bete OP inidde= (£ _ Write: re gram to.read in an array of names and to sort them In alphabetical | Fit (n==* (é order. User sort function that receives pointers to the functions strcmp ans . fF {is_g swap. Sortiin-turn should call these functions via the Pointers. else if (n include
0)swap(s{i],s[3]) void-swap (char *s1, char *s2) “fven an array of sorted list of integer numbers, write a functlon.to search fora pzrticular item, using the method of binary search. And also show how this function may be used in a program. Use pointer‘and pointer arithmetic. ) include
. #define N 5 | main () { int arr ([N]= {-3,2,6,100,645},x, iEisirst>tase) gota! niddle= (firet+last)/: 4£(n==* (armiddle) ) {is_got=iniddle;goto ay) “else if (n<* (at e)) : last=middl else o8 first-middle+t; goto a2; al: return is_got; Module 3.8 - File Management in ¢ 1. Write a program to copy the content of one file into other. #include
pmind al FILE *fpi, *£p2; . oe vba char c; | fpi=fopen ("input .txt*,*r") ; ICE, V.V.Nagar -fp2=fopen(*output.txt","w"); * while ((c=getc (fp1)) !=BOF) (pute (c, fp2) ; } } 2. Two files DATA1 and DATA2 contain sorted list of Integers. Write a program jong produce a third file DATA which holds a single sorted, merged list of these tw lists. Use command line argument to specify file names. “AB ei arc #include
se : . main(int argc, char *argv{]) ' ' { 1 PILE *£1,*£2,*£3; 1 int a[5],b(5],c[10] ,i=0,5=0,k,1; s if(arge!=4) (printf("Error : Incorrect no. of argument's\n") ;return 0 I f1=fopen(argv[1],"x"); ‘ ‘open (argv[2],"r" f £3=fopen(argv(3],"w"); E for (i=0; i<5; +44) (ali]=getw(£1) sbLi]=a s iz0; 1 for (k=0; k<10; ++k) . } { i | clos i£(ali]
pa struct customer “ { char name[20] ; long t_no; a Ap 7 As: Of struct “BP char « main() { NICE, V.V.Nagar - Ph. (02692)238534 : 174struct customer c[10]; » char ch,n[20]; F long no; } int i=0,5; PILE *£1; se fl=fopen ("custom.dat", “w") ; : printf("\nEnter data for customer # %d\n",i+1); printf ("Name ': "); scanf ("%s",c[i] name) ; print £("elephone No : "); scanf ("%1d", &c[i] .t_no) ; | fprintf£(f1,"%s %1d\n",c[i] .name,c[i].t_no); printf ("\nMore Customer ? (y/n) : "); ch=getche (); ite; }while(ch=='y'||ch=='¥") ; fclose (£1); fl=fopen("custom.dat","r"); for (j=0; j
° ae ‘class Test . 4 EES { . ae public: “ void show() wie {cout << *I am a member function ‘of* class\n";void main() { Test t; t.show(); A show(); ‘ mo } 2, | void show() , 8 { a 4 out << “I am a function defined outside the class\n"; - | } - * /* OUTPUT Q: Des I am a member function of class A: Ade y am a function defined outside the class } constr ye Q: Sta Q: State whether the following statements are TRUE/FALSE. 1 4. Data items ina class must always be private : | 2. 2, Afunction designed as private is accessible only to member functions of that class. 3. 3. Afunction designed as public can accessed like any other ordinary function 4. 4. AClass brings all aspect of an entity in one place, 5. 5, Class members are public by default “
Destructor . 1. Its name is same as. class, name 1. Its name is same as class name pre- ceded by ~ (tilde). 2. Itis called automatically when an 2. [tis called automatically“ when an object is created. objectis destroyed. 3. [tan any number of 3. Itnever takes any argument. arguments. 4.Normally new is used in 4. Normally delete is used in | constructor to allocate memory destructor to free memory from. to objects. Objects. - SoBe Module 4.3 : Operator Overloading @ What is operator overloading? “A; C++ permits us to add two variables of user-defined types with the same syntax that is applied to basic data types. This means that C++ has the abllity to provide the operators with aspecial meaning for a data types. The mechanism to give special meaning to an operator isknown as operator overloading. .Q: Why Is it required to overload operators? A: Operator overloading provides the flexible option for the creation of new definitions for} most of the C++ operators. We can almost create anew language of our own bythe creat use of the function and operator overloading techniques, ‘ + Q: What Is an operator function? Describe the syntax of an operator function. , A: To define additional task to an operator, we must specify what it means in relation to theme. class to which the operator is applied. This is done with the help of a special function, calted operator function, which describes the task. The general form of operator function is: * ’ Return-type class-name :: operator op (argument-list) { function-body a } Q: How many arguments are required in the definition of an overloaded unary op" o erator? A: Only one. Q: State whether the following statements are TRUE or FALSE... . Using the operator overloading concepts, we can change the méaning ofan: operator. 2. Operator overloading works when applied to class objects only. . . When using an overloaded binary operator, the left operand isimplcty passes tothe © member function. . ‘The overloaded operator must have at least one operand that is user-defined ‘ype. . Operator functions never retum a value. .. Through operator overloading, a class type data can be Converted j in to basic type data. 7. Aconstructor can be used to convert a basic type to a class type data. Answers 1. TRUE (You can overload * ‘+’ to subtract) 2. TRUE- 3. TRUE (The right operand is passed as argument to the operator routine) 4. TRUE (Otherwise the routine for basic data type will be called) 5. FALSE : bP @®| 6. TRUE : @ 7. TRUE epn OnE Module 4.4: Inheritance 4 Q: What does inheritance mean in C++? . ] ‘A: C++ supports the concept of reusability (use something which already exists rather than , trying to create the same all over again). It saves time and money, Reusability is implemented in C++ through a mechanism called inheritance. Inheritance is a mechanism of deriving a new class from an old class. The old classis referred as the base class and the newsclass is ao referred as the derived class, “4 . Q: What are different forms of inheritance? Explain with syntax. ; r (@) Single inheritance ~ po Class B(derived class) is derived from Class A(base class). x RICE, V.V.Nagar - Ph. (02692)238534 86ns for 2ative tothe ; valled ~ yop rthan ented vinga ° assis class A ¢ di to ‘ class B : public A . i im) Mute inhertance Class C(derived class) is derived from Class A(base: class) and Class Bibase class). s class A { di class B C vi class C : public A, public B { : ve (c) Hierarchical Inheritance 5 Class B, C and D(derived classes) are deriv class AU dF 5 class B: public. A { ‘ whe (d) Multilevel Inheritance Class ¢ (derived classes) Is derived from Class B (which acts a as base class forclass C but de ived class for class A) whichis in ‘urn derived from class A. class A class B: public A class és public B (@) Hybrid inheritance Z Class D (derived class) is derived from class B and C (derived classes for: class A but base classes for class A) that are derived from class A. aa class A i d; . fe NICE, V.V.Nagar - Ph. (02692)238534 "185er ————————— class B: public A { ve ye class C: public A { di class D : public B, C { Vi ' Q: We know that private member of base class Is not inheritable. Is it anyway sible for objects of a derived class to access the private members of the basec! If yes, how? Remember that the base class can not be modified. : Bete A: For that, we can use public member function of derived class which in turn use (or calls |’ public member function of base class that uses the private data member of the base class} |. Belowis the syntax to implement this. Pees . i #include
class base < private: : i int.x; public: base () ‘ ‘i (x=57) int getX{) {return x;} fi de || class derv : public base i { public: “ int getBaseData() F - {return getX();) vi void main() E { aw \ derv dy sf or H cout << ‘d.getBaseData(); th t ) Po ry : ; /* OUTPUT of ‘A _— . id POL Q: Glass D Is derived from class B. The class D does not contain any data member of its own. Does the class D require constructor? If yes, why? . . A: It does not require constructor in derived class because ithas no data member. Itcan use constructor of base class. The above program shows. ‘the situation. Q: State whether the following statements are TRUE or FALSE. (a) Inheritance helps in making a general class in to more specific class. crmawoe NICE, V.V.Nagar - Ph. (02692)238534 186 |y pos- class? recalls) ‘class. built, | Q: What does polymorphisin mean in C++? * operators. The overloaded functions are “selected” for invoking by mi (b) Inheritance supports data hiding. (c) One of the advantages of inheritance is that it provides a conceptual frame work. (d) Inheritance facilitates the creation of class library. : (e) Defining a derived class requires some changes in basé class, : . * (f) Abase class is never used to create objects. (g) Itis legal to have an object of one class as a member of another class. Answers (a) TRUE (b) TRUE (c) TRUE (d) TRUE (e) FALSE (f) FALSE (g) TRUE Module 4.5: virtual and friend funetion/class, this Polntar Q: Explain the concept of virtual base class? * onsider a situation where all the three kind of inheritance, nariely, multifevel, multiple 4f and hierarchical inheritance are involved. For example, class “child” has two diréct base classes “parent1” and “parent2” which themselves have a common base class “grandpar- ent’. The “child” inherits “grandparent” via two separate All public and protected members of “grandparent” ar inherited into “child” twice; first via ‘parenti” and second via “parent2”. This means “chil t members inherited from “grandparent”. This introduc: The duplication of inherited members due to these multiple ‘paths | 36 avoided by mak- ing the common base class as virtual base class while decla agen orintermediate base classes as shown below. es class .grandparent { ds ‘ ‘ class parentl : virtual public grandparent ( : " d; Wiebe g tf lass parent2.-: virtual. public grandsarent { Ye . : . class chila : public parenti, public parent2 C dG ” . When the class is made a virtual base class, C++ takes necessary cé care to ‘see that only one copy of that class is inherited, regardless of how many inheritance paths éxist betweer the virtual base class. ‘ vane + ‘Q: What is an abstract base ciass? A; An abstract base class is one that is not used to create objects. An‘ abstract class! Is designed only to act as a base class (to be inherited by another class). It is designed concept in program development and provides a base upon which other classes canbe A: It simply means “one name and multiple forms" or' ‘giving diferent meaning! to te ‘same thing”. The concept of polymorphism is implemented using the. overloaded functions, and NICE, V.V.Nagar - Ph, (02692)238534muy type unl Haws HENS HHUTITGUON IS KOOW! LO tne Compiler at tne Compile time: therefore compiler is able to select appropriate function calll atthe compile time itself, I is called early binding or static binding or static linking. ° 4 Itwould be nice if appropriate member function could be selected while the program is’ tunning. This is known as runtime polymorphism. C++ supports a mechanism‘known as. virtual function to achieve runtime polymorphism. Q: What Is a pure virtual function? A; A pure virtual function is a virtual function with no body. me ‘Syntax: virtual void show()=0. . : Q: Write the major rules for defining virtual functions. 1. The virtual functions must be members of some class. 2, They cannotbe static members. ‘ a 3. They are accessed by using object pointer. ; “ 4. Avirtual function can be a friend of another class. sy ofa 2 5. Avirtual function in base class must be defined even though itmay notbe used. 6. The prototypes of the base class version of a virtual function and.alll the derived cla versions must be identical. If the two function with the same name have different p totypes, C++ considers them as overloaded function Virtual function me nism is ignored. ieee 3, Shae : : 7. We can nothave virtual constructors but we can have virtual destructors. 8. While a base pointer can point to any type of derived object, the reverse is not Thats to say, we can not use pointer to a derived class to access an object of : Q: Ex] 9, When a base pointer points to a derived class, incrementing or decrementing it nee not make itto point the next object of the derived class, Itis incremented or decreme! ep only relative to its base type. Therefore, we should not use this method to move’ interat pointer to the next object. 10.. Ifa virtual function is defined in the base class, itneed not be necessarily redefinedg- Exam the derived class. In such cases, calls willinvoke the base function. s Module 4.6 : General Question Q: Explain enumerated data types with example. . . A: An enumerated data type Is another user-defined type that provides a way for attachi names to numbers, thereby increasing comprehensibility of the code. The enum key automatically enumerates a list of words by assigning them values 0, 1, 2. and so on. facillty provides an alternative means for creating symbolic constants. Example: #include
void main() { on “y enum weekdays{sunday, monday, tuesday, thursday, ... friday saturday}; an Sloe int day; cout << “Enter day number (0-6) : “; cin >> day; NICE, V.V.Nagar - Ph. (02692)238534ad. dclass int pro- necha- ot true. of base git will aching ayword n. This iday, 188 | OUTPUT .1 : NICE, V.V.Nagar - Ph. (02692)238534 rst switch (day) . : { case sunday: cout << “Sunday”;break; case monday: cout << “Monday”; break; case tuesday: os cout << “Tuesday";break; case thursday: ‘ . cout << “Thursday* ;break;, case friday: wal cout << “Friday";break; .; case saturday: : cout << default: cout << } “Saturday; } Enter day number (0-6) Monday OUTPUT 2 Enter day number (0-6) : Invalid Day Number Q: Explain the use of reference variable. In Cee. A: C++ introduces a new kind of variable known as the reference variable. Areference var * able provides an alias (altemative name) for a previously defined variable. For example, we make the variable sum a reference-to the variable total, then sum and total can be use interchangeably to represent that varial : Example 1:9 © #include
void pain) float total=100; void change(floata) ; change (total); gout << total; r 189void ‘change(float &sum) { sumtt; } gurrur 7 * 101 Q:.Show and explain bastc structure of C++ program, A: Typically a C++ program contains tolewing four sections. 1. Include Files 2. “Class Declaration : 3, Member function definitions - . 5 | ‘4... Main Function program ] Commonly, we organize a program into three separate files, The class dactarations areplaced | ina header file and the definitions of member functions go into another file. This approach | a enables the programmer to separate the abstract specification of the Glass. definitjons fram the implementation detail (member functlan definition), Finally the main, -program uses the class placed’ In the third file that “includes" the, previous two files as well as any other files required. . Wah Filel.¢pp: j class temp eo t-. ‘private: ‘ public: int sum(int, int); we: ' File2.cpp: #include “filel\cpp” dnt temp :: pum (ing, x, int y) aa cout <2 “File 2 called"; retyrn x+¥7 . oy : File3.cpp: #include
1, #include “file2.cpp* void main() ron seme ti. "a Epis the concept of default arguments. A; C++ allows us to call a function withgut specifying all'its arguments, In such cases, the function assigns defauit value to tha parameter which does nothave a matching argumont in- thefuhction call. Default values are spedifiéd when the function isdeciared. Soe the folawing example... , #include’
'- ‘glass interest -public: { interest p; cout << p. amount (1000, cout << p.amount (1000, Following example shows hows endl at #include
include
//. f void main() setw Noe € 2 int basic=950, allowances! F #include,
, Hinclude
include
{.#define pi 3.14159 void main() { he cout << setprecision(3); cout << sqrt (2) << endl; cout << pi << endl; return p*r*n; ' Q: Explain the following manipulators with example. bie, -(@) setw() (b) setprecision() (c) setfill a me float amount (float p, int n, float r=0.15) 5,0.12) << endl; 5) << endl; saiacanniecinp inprowras. } total=1045; Si setw(10) << basic << endl.OUTPUT 1.414 3.142 Setfill function can be used to fill the unused positioned by any desired character. Iti is used | the format: setfill(character). Refer the following example: ° 3 #include
#include
void main() . { . : : cout << setw(10) << setfill(‘*") << 5250 << endl } . oureur ireH#5 250 | setiosflags an #include
#include
#include
#define pi 3.14159 void main() vendl; 4 cout << setw(10)- } ey * Q: Explain inline function. " . of . I A; Every time a function is called, it takes a lot of extra time in executing a series of instruc-: tions for tasks such as jumping to the function, saving registers, pushing arguments into stack: and returning to the calling function. When a function is small;a substantial perce: execution time may be spentin such overhead. One solution to this problem is tomake the function inline, af fe ay Aninline function is a function thatis expanded in line when itis invoked. Thatis,the compiler: replaces the function call with the corresponding function code. The inline functions are de- fined as follows: ARIAS ao nt Intine function-name * . é ue { . function body | NICE, V.V.Nagar - Ph, (02692)238534agMODULE - 5.1 : OBJECT AND CLASSES maf lew y/ Pros // Program 1 won : . » 7/ Vexy simple program indicating use of object and‘ cla: - #include
«Class TestClass void set (int a) Seat yo. void main() { TestClass t; t.set (12); teshow(); gerehC) 5 Q y // Program 2 U/ Multiple object! #include
class TestClass".” public: vola void show() . { . cout << data << endl; . ’ } we Me nm void main() oe {TestClass t1,t2; ‘ t1l.set (12); t2.set (24); t1.show(); t2.show(); } NIGE, V.V\Nagar - Ph. (02692)230534W/ Program 3 we // Constructor include
2 nethoxs hoot ‘no, tii TestClass() { cout << ) void set (int d) { data=d; , void show() “void main() € TestClass ti,t2; tl.set (12); t2.set (24); t1.show(); t2.show() 7 dinclude in b>” q class postclase, ‘ estClass (int a) fatard; void show() { cout << data << endl; .TestClass t1(12),t2(24); tL.show(); t2.show() } // Program 5 7/ More on constructors and functions #include
class Counter { | private: » int c; public: Counter () { e=0; void plus (void) { cH void minus (void) Counte: cl.plus(’. el.plus()¥ c2.minus () 2.minus () cl.minus (); c2.plus(); el.show(); c2.show() 7 , progean 6 A Destructor jinclude
class TestClass © { private: NICE, V.V.Nagar- Ph. (02692)208594int t; public: TestClass () { . ‘ cout << “Hello I ama contructor\n?; } . ~TestClass () { . i cout << “Hello I ama destructor\n"; } void set (int d) t ted; 3 void show() { cout << t << endl; } ie ctor juctor di voidmain() ~ . { TestClass obj1,obj2; obj1.set (12); obj2.set (24); y objl.show(); 9s sa. obj2.show(); . . cout << “This is the last statement of program\n”; } // Program 7. (7 Overloaded Constructors (More than one constructors in a class) .» * #include
- class Data { private: } cout << “I ama constructor without argument \n"; d=0; . } Data (int dt) C cout << “I am a constructor with one argument \n”; deat; } void show() : : a eee NICE, V.V.Nagar - Ph. (02692)238534 : 197¢ . Pdf. cout << d << endl; us } #in void add(Data obj1, Data obj2) : cla { . - d= objl.d + obj2.d; - ., JF, void main() t am a constructor without argument t I ama constructor without argument! Data dl (12) ,d2(24) 43; I am a constructor. with one d3.add(d1,d2) 7 . 3..show(); . } // Program 8 E // Member Function Defined Outside the Class #include
class Data Data() © . i { el ‘cout << “I ama constructor without argument \n"; 4 Data(int dt)” voi t cout << “I ama constructor with one argument \n"; d=at} } void show(); . void add (Data, Data) ; ra u “a | void Data :: show() ‘ tir { cle cout << d’<< endl; } | void Data :: add(Data obj1, Data obj2) | { d= obj1,d + obj2.d; | } I ama constructor without argument! | void main() I ama constructor without .argument { ° I am a constructor with one Data dl (12) ,d2 (24) ,d3; 43 .add (41,62) ; 3.show(); } | NIGE, V.V.Nagar- Ph. (02692)238534 : 198 NIC//, Program 9 // Returning object from member function #include
class Data . a { private: int d; public: sent. Data () sent. t | 4-0; } Data(int dt) { asdt; } ! : void show() i { j : cout << d << endl; } Data add(Data obj) { aes Data tempobj; tempobj.d = obj.d + 4; return tempobj; } : da . BP OUTPUT void main () a lo t oe 36 i Data d1(12),d2(24),d3; d3=A1 add (d2) ; 43. show() 7 } // Program 10 // Member Function.to square private data #include
class Data " private: int d; public: © Data() { d=0; } ~ Data{int dt) { dedt; 198 NICE, V.V.Nagar - Ph. (02692)238534} void show() { cout << d << endl; } Data squarel (void) C MW | Data temp; my temp.d=d*d; #inc return temp; clas } void square2 (Data obj) { d=obj .d*obj.d; a , void main() { Data di (12) ,d2,d3; d2=d1 squarel () ; . : 3.square2(d1); //An alternate approach. // Carefully objserve the difference between two functions. d2.show() ; 3. show() ; é } // Program 11 // Write a program to de wito2 3. 5 #include
void class fibo i | ‘ , i private: i int/n; public: void generate(int m) MU Px i c I cx nm integ int i,tl=1,t2=0,t3; the a + for(isl; i<=n; ++i) Hincly { . ‘ class t3=t1+t2; ' cout << £3 << “\t";void main() { fibo £; £.generate(10); } // Program 12 // Write a program to average N numbers, #include
class number { private: int n; int arr [10]; ~ public: void read() { cout << “How many elements 2” cin >> n; | : cout << “Enter “ <
s\arr[i];} float average() { float sum=0; for (int i=0; icn; +44) (sum=arr[i];} return sum/n; + OF How many elements ? 5 void main() { number obj; obj.read() ; cout << “Average = ” << obj saverage(); } : d/ Program 13 /* Create a class point having data member x and Y of type integer. write member function to input two points end display the addition of two points. +/ #include
class point { private: int x,y; public: point() — (x=0,y=0;) read() { NICE, V:V.Nagar - Ph. (02692)236594 ° - 201If Pro cout << “Enter x: “; cin >> xj (1 Bxa cout << “Enter y: “; cin >> yi — ). #inclu showadd() class ¢ { « cout << “Addition of x andy : “ << xty << endl; P } : Vi void main() f point pr Enter y : 10 p.read() Addition of x andy : 15 { p.showadd() + }. 7] Program 14 Bibi, // Write a program to generate following series. (5/100) + x*n/al TL Yuxrx*2/21+ KAB/Bl+. 2 ee by . jinclude
an class series ° , 2 t private: float x; int n; public: : void read. { cout <<.“Enter x: “7 cin >> x} cout << “Enter n: *; cin >>; dots void show.()° “ Lieut | Eloat uppex=1.0, lower21.0, sum-07 1 ~ for(int i=1; i<=n; ++i) % { SoS upper*=x; lower*=i; sumt+=upper/ lower; } cout << “Answer = “<< sum; } hi void main() to Enter n: 3 series s; answer = 5.333333 s.read(); s.show()i } NICE, V.VNagar - Ph. (02692)23853411 Program 15 // Example of function overloading. #include
class over . { public: int add(int x,int‘y) (return x+y;) int add(int x, int y, int z) {return x+y+z;} double add (double x, double y) {return x+y;} void main() - { over 0; cout << o,add(5, 10) << endl; cout << 0.add(5,10,15) << endl; cout << 6.add(5.5,10.10) << end! } “Calls second ‘function ‘Calls third function // Program 16 /* Create a class named student havii rollno and three marks. Write 4 member £ (a) input name, rollno and marks . 4” (b) Calculate percentage':, — (c) Display all the information. “/ #include
F class student t ‘private: int rolino; char naine[20] ; int mL, m3; float per Lic: . void read() tid gout << “Enter rollno cin>>> rollno; cout << “Enter name : “; - . cin >> name; cout << “Enter three marks cin >> ml >> m2 >> m3; . void caiculate() C perc= (mi+m2+m3) /3; } void Show() “ << rollno << “ Name : “ << name cout << “Rollno 2 | NICE, V.VNagar - Ph. (02692)236534 ° 203<< endl; . 4 << endl; cout << “Percentage : “<< perc<
#include
class cricketer { private: char name{20]; int age; ° char country [20]; char type[20]; int totalmatch; public: nas bgt “cricketer () { “name[0]="\0"; age=0; country [0]="\0'; type[0]="\0"; totalmatch=0; . ) void read() { cout << “Name : “; cin >> name; cout << “Age : “; cin >> age; cout << “Country : “; cin >> country; cout << “Type : "; cin >> type; cout << “Total matches : “; cin>> totalmatch; } i NIGE, V.VNagar - Ph. (02692)238534 ricketers.*/ cout << "Marks +" << ml << /\t! << m2 << ‘\t! << mdvoid show() { cout << “Name : * << name << endl; cout << “Age : “ << age << endl; cout << “Country : ” << country << endl; cout << “Type : “ << type << endl; cout << “Total matches 3 “ << totalmatch << endl; } de void main() { cricketer c[100]; for(int i=0; i<100; +44) t cli] .xead(); } for (i=0; i<100; ++i) ‘ ‘ cli] -show(); } } /* Program 18 Write a program to declare a class string with menber ariable char *str and needed member functions, also write a member function to convert string object to uppercase. */ #include
class string { By private: char *str7 wpublic: void read() { cout << “Enter string : “; cin >> str; void show() cout << str << endl; , void toupper () while(*(str+i) !="\0") d£(*(str+i)>s'a! && *(str+i)<='z!) { * (str4i)-=32; NICE, V.V.Nagar- Ph. (02692)238534 : oidi void main() { string s; OUTPUT s.read(); Enter strirg : Hello s.toupper (); HELLO s.show(); << } /* Program 19 Create two classes DM and DB, which store the values of distances. DM stores distances in meter. “and, centimeter and DB 12) in feet and inches. Write a program that .can read values for the clags objects and add one object. 298 pu with: another object of DB.+/ : 2 : #include
class DB co voi private: int feet; int inches; public: void read() t 3 ‘Out << “Enter feet and inches : cin.>> feet >> inches; rout << “Feet : “ << feet << “ Inches : “ << inches << endl; int rettirn_feet () { return feet; } int return_inches() { return inches; y , class DM { private: int mtr; ~ (02692)238534 NICE, V.V.Nagar - Ph. vr 7 +int om; public: void read() { cout << “Enter meter and centimeter : “7 cin >> mtr >> cm; void show() : { cout << "Meter : “ << mtr << “ Centimeter : “ << cm << endl; } void add(DB db) )+(db.return_inches () / =a { 42) )/3.25 float meter_om= (db. return_i int meter=(int)meter_cm; « int centimeter= (int) ( (met mer+=meter; ae om+scentimeter; } a void main() am. read() 7 db. read(); dm. add (db) dm. show () 5 } 4 /* Program..20 : ‘A bookshop maintains the inventory of books that are being sold at the shop: The list includes details such as author, title, price, publishers and stock position. Write a member function to add new books and list the authorwize.*/ #include
- #include
#include
#define MAX_BOOKS 100 class book_list t private: char author [MAX_BOOKS] [20]; char title [MAX_BOOKS] [20]; int price [MAX_BOOKS] ; char publisher [MAX_BOOKS] [20]; NICE, V.V.Nagar - Ph. (02692)238534 207a int stock_position; public: book_list () {stock_position=0; } void add_newbook () {fflush(stdin} ; cout << “Author : “; . cin >> author [stock_position) ; fflush(stdin) ; cout << “Title : “; cin >> title[stock_position]; f£flush(stdin) ; cout << “Price : "; cin >> price[stock_position]; fflush(stdin) ; cout << “Publisher : cin >> publisher [stock_position] ; stock_position++; } void show_list_authorwize() ¢ : int tempprice; char tempauthor [20]; char temptitle(20]; char temppublisher [20]; for(int i=0; i
0) { strepy(tempauthor,author[i]).; strepy(author{i] ,author[j]); strepy (author [i] , tempauthor) ; strepy(temptitle,title[i]); strepy(title[i],title(j]); strepy(title[i],temptitle); tempprice=price[i]; price[i]=price[j]; price[i]=tempprice; strepy (temppublisher, publisher [i]); strepy (publisher (i],publisher[j]); strepy (publisher [i] ,temppublisher) ; } } cout << “t\tAuthorwise listing\n"; for (i=0; i
#define size 4 class matrix { private: int a[size] [size]; public: void read() { for(int i=0; i
> alillil: ) } void show()” for(int i=0; i
. , class Increment { private: int data; public: Increment () ( data=0; ) int display () t : Seout << data << endl; }. = * void operator ++ () SY data ++; } Ve void main) { Increment obj1,0bj2; * [OUTPUT objl.display (); obj2.display(); Objl++: ++objl; obj2++; obj1.display ()7 obj2.display(); } PNOO NICE, v.v. \. (02692)238534 . 211¢/ Program 2 . : // Overloading ++ operator with returning an object . j ~ #include
class Increment { private: int data; public: Increment () { data=0; } int display () { cout << data << endl; } Increment operator ++ () voic MW} Me #ine clas Increment temp; “> data +4; temp. data = data; return temp; } hi void main() { OUTPUT Increment obj1,0bj2; objl.display.(); obj2.display (); objlee; obj2=obj1+4} obj1.display(); obj2.display(); } Nwooe // Program 3 // Overloading arithmetic + operator #include
class Data { private: int d; public: Data() : {d=0;} Data (int dt) {d=dt; NICE, V.V.Nagar - Ph. (02692)238534 : 212 &} NICE,} . void show() { . cout << d << endl; . + } Data operator + (Data obj) { Data temp; temp.d = obj.d +d; return temp; : } t de void main() { Data dl (11) ,d2(22) ,43; d3=d1+d2; 3. show(); } // Program 4 // Overloading arithmetic + operator #include
class Height { . private: . ! int feet; float inches; public: : Height () : t | feet=inches=0; . -- } Height (int £, float i) { feet=£; inches=i; } void show() { cout << “Feet = “ << feet << “\tInches = * <« inches << endl. } Height operator + (Height h) { Height temp; _ temp. feet=feel +h. feet; tenip. inches=inches+h. inches; if (temp. inches>=12) C temp. inches-=12; NICE, V.V.Nagar - Ph. (02692)238534Ce temp.feet++; > } return temp; } . . is Me . void main() . void t Height H1(5,10) ,H2(6,11),H3; H3=H1+H2; H3.show(); } // Program 5 il ® // Overloading arithmetic + operator . . 11 © // Bvaluating H2 = Hl + 10.5 type of we #include
Hind! class Height tine! t class private: int feet; float inches; ~ public: Height () { feet=inches=0; + . : Height (int £, float i) t ; ‘fleet=£; inches=i; yo ~fsHeight (float t) : { : feet = int (t); “inches = 12* (t-feet) ; ° Boe void shéw() { cout << “Feet =” << feet << *\tInches = “<< inches << endl; 3 Height operator + (Height hh) Height temp; temp.feet=feet +h. feet; - , temp. inches=inches+h. inches; if (temp. inches>=12) < temp. inches-=12; temp.feet++; INICE, V.V.Nagar - Ph. (02692)238534 214 F- —return tempy q } . di void main() Height H1(5,10) ,H2; H2=H1+10.5; H2.show()7 } // Program 6 // Overloading arithmetic + operator 7/ Coneatenating two string objects jinclude
, #include
class String private: char str [80]; public: String () { strepy(str,”” . } . string (char 8[801) = { stropy (sts) te ‘ void display () ° t cout << str << endl; } ve String operator + (String s) {£(strlen(s.str) +strien(str) <80) { : string temp; strepy(temp.str, str]; streat (temp. str,s.Str) 7 return temp; else { cout << “Resultant string too large”; + y oe 214 [Nagar - Ph (02692)238534 «void main() { . String s1("NICE Creates ”),s2(“Good Computer Frogrammers“) ,s3; s3=s1+582; s3.display(); OUTEUT } // Program 7 // Overloading comparision operator > and a= tinclude
‘lass Data { private: int d; public: . Data () { d-0; } Data (int dt) { dt=0; eh ) int operator > (Data obj) ¢ if (4 > obj.d) return 1; else return 0; INICE Creates Good Computer Programmers } int operator == (Data obj) { if (4 obj.d) return 1; else return 0; { OUTPUT Data t1(12),t2(24); if(t1==t2) cout << “Equal”; else i£(t1>t2) cout << “Greater”; else cout << “Smaller”; Smaller f. progran 8 / Overloading += operator nclude
ass Height { private: int feet; ICE, V.V.Nagar - Ph. (02692)238534 > 216.float. inches; public: Height () { feet=inches=0; ? Height (int f, float i) { feet=f; inches=i; } void show() : { Sour : Cout << “Feet = “ << feet << “\tInches = ¥ << inches << endl; ) ‘ f void operator += (Height h) { feet += h.feet; inches += h. inche; if (inches>=12) { ae “void main() : wt Height H1( H1+=H2 HL. } : ‘V/ Program: 9 SL OE Mates ye “Sy, 11 Write a C4 program to overload following “Binary: operators. Mo lee 2. a 3, a. / ebay! , #include
‘ #define PI 3.1415 class circle- private: , ; int rad; . . public: circle(int r) : : (rad=r;} float area() {return PI*rad*rad;} (02692)298534int operator > (circlet) ~ = « ig (rad > t.rad) return 2; else return 0; [OUTPUT 3 Area of circle cl : 314.149994 Area of circle-c2, :, 1256.599976 is greater than cl . YE void main() { circle c1(10) ,c2(20); Area of circle c2 cout <<-*Area of circle cl : “7 cout << cl.area() << endl; cout << “Area of circle c2 : "; : cout << c2.area() << endl; . if (cl>c2) : {cout << "Area of circle ‘cl is gréater than c2";} else {cout << “Area of circle c2 is: ae = than cl"; 7* Program 11. Declare a class to represent dal suitable member and data. Overload . age of a person. Use birth date and te #include
dass date ssume calculate t private: int dd,mm,yyi. public: : cout << “Enter date (dd mm yy) :""} -cin >> dd >> mm >> yy; * , void show() {cout << dd << "2" << mm << “:" << yy << endl;) date operator - (date t2) | int month[12]=(31, 28, 31,30,31,30,31, ah, 30,32,30,31} int total_days=0; total_days+=((yy-1)-(t2.yy+1)) $365; 4£(( (t2.yy%4==0) && (t2.yy#100!=0)) month[1]=297 . (t2!yy%400==0) ) 218 3. (02692)238534total_days+=month{t2.mm-1]-t2.ad; for(int ist2.mm; i<12; +44) { . total_days+=month[i] ; mo ee } Af (( (yy84==0) && (yy%100!=0)) | | wytdooen =0)) month[1]=29; else month[1]=28; for (i=0; i
class complex { private: int x,y; public: complex () {x=y=0;} complex(int xx, int yy) . (xsxx;y-yy7 £ } . . : NICE, V.V.Nagar - Ph, (02692)230534void read() { , cout << “Enter x andy : “7 . cin >> x >>¥7 ‘ 3 mn complex operator + (complex c2) { complex temp; * temp.x=x+02..X: temp.y=ytce2.¥7 return temp; } void show() ne p3=pl+p2; 3 show () minute=m; second=s; . ) oR void show() ( cout << hour << “:" << minute << “:7 <<’second << endl; y time operator + (time t) { time temp; at . ! temp-hour=hour+t.hour; - temp.minute=minute+t .minute; NICE, V.V.Nagar - Ph. (02692)238534temp.second=second+t .second; if (temp. second>=60) { temp .second-=60; temp.minute++; } if (temp.minute>=60) . { temp .minute-=60; temp.hour++; an } return temp; } de void main() { , time t1(20,30,40) ,t2(5,10,15) ,t3; t3stl+t2; t3.show() ; } MODULE // Program 1 // Simple Inheritance #tinclude
class Base Oe, cout << x << endl; : Bd } class Berv 1 public Base 4 t public:. Derv() { x=0; } void minus () - - NICE, VV.Nagar -Ph. (02692)230504- ye void main() { Derv obj; nur obj .plus(); 2 obj.plus(); . obj..plus()7 coe obj minus (); oO “ obj.show(); “ program 2 7/ Derived Class Constructor “ginclude
class Base protected: int x; public: Base() { x20; uigea } i void plus() = w << x << endl; dF ‘ class Derv : public Base a . { 2 we private: ~ wna int yi a public: Derv() + Base() Ba e ( 2 cout << “Derived Class Constructor\n"; y=0; : . oY void minus ()} ’ void showDerv() { cout << “y = 4 << y << endl; - oak , void main() . { Derv obj; ‘oureur obj -plus () ; Base Class Constructor obj .plus(); Derived Class Constructor a obj.plus() ;- x= 2 obj -minus () ; obj. showBase () ; obj .showDerv() ; “ Progran 3 ye Create a class person having menbers 1 class student having member teacher having member sala: ite ne to initialize, read and write data. Also function. rs ay #include
. #include
," class person ys -1 and af “Derive a “ive: another, class Fy member, function voi ‘toto char n[20], int a) “aerepy (mane, a); ee ag: void display 0 € cout << “Name :-" << name << endl; cout << “Age : “ << age << endl; your #inc Me clas class student : public person * : oe : t private: float perc; public: NICE, V.V.Nagar - Ph. (02692)238534 NICEstudent (char n[20], int @, float p) + person(n,a) pere=p; : tet ‘ } “ void display () { cout << “Student” << endl; person :: display (); a cout << “Percentage : * << perc << endl; } - 3; . a : “ class teacher : public person { private: float salary; public: teacher(char n[20}, int a { salary=: } void display () { ye void main() Percentage : 78.900002 Teacher Name : D.H. Patel Private and public inheritance ~ This program will not compile and run. Watch the errors - carefully. To understand this program, refer the diagram” arawn dn your class-notebook. */ #include
class base { private: int a; Protected: int b; public: int c;: public base ~ C2 void display1() cout << a << endl; //Error an cout << b << endl; cout << c << endl; } i class derv2 : private base { int public: void display2() { cout << a << endl} //Error cout << b << endl; : cout << c << endl; + ve void main() C derv1 dl; derv2 42; 1) Program 5 77 Maltiple Inheritance #include
class A 2 : eo. Srotected: . int a; * public: A(int x) {a=x; } void display () {cout << a << endl; } INIGE, V.V.Nagar- Ph. (02692)238534class B { protected: . : + int b; . public: B(int y) { bey? } void display () { cout << b << endl; J vi class C: public A, public B { private: int oc; public: Caz; } void display'() Cae // Program 6 // Ambiguity in Multiple Inheritance #include
class A C . public: 2 ‘ "void display() : “ aa { cout << “Class A" << endl; d. oa NICE, V.V.Nagar - Ph. (02692)238534 TE ata gayoid display () . : 2 { : . Tee pg cout << “Class B” << endl; 4 } : Me class C : public A, public B { ye void main() { C obj; obj display (); // Error (I£ you remove second statment from main, then you will get following output) /* Program 7 Assume a class cricketer. class batsman from cricketer. Data member of bats Total ve performance. Member functions, Tap gata, @isplay data. */ |. #inelude
class cricketer ‘ / U at | : . 1. | “gout << “Name : “; cin >> name; . Fc a c i void show() ‘ : cout << “Name : “ << name << endl; ” t cout << “Total Matches : “ << total_matches << endl; } yi q - class batsman : public cricketer .o . 5 i { . . 4 ' private: int total_runs; int average_runs; int total_matches; NICE, V.vV.Nagar- Ph. (02602)238534int best_performance; public: void read() { cricketer :: read(); Lo . cout << “Total Matches : “; cin >> total_matches; cout << “Total Runs : “; cin >> total_rung; cout << “Best Performance : “; cin >> best_performance; void calculate() {averagé_cuns = total_runs/total_matches: } void show() € cricketer :: show(); cout << “Total Matches ; cout << “Total Runs cout << “Average : “ cout << “Best Performance ance << endl;, } i ere yi void main() { batsman b; + bread (); Begt Performance: : 189 b. calculate ( ‘ou have entered ae cout << val sot b.show() #2, Total Matches : 208 } Total Runs : 9876 .s Average : 47 i Progra: ; Best Performance :.189 A Exazipl Les. ¢ Li 1 and Multilevel Inheritance ‘Finclude
° private: - . char name[20] ; int year; . public: os void read) cout << “Enter name : *; cin >> name; cout << “Year : "; cin >> year; 5 : void show() . { cout << “Name : * << name << endl; cout << “Year : “ << year << endl; NICE, V.V.Nagar - Ph. (02692)238534 - 229} m class teaching : public college private: int no; public: void read{) € college: :read(); cout << “Enter no of employees : *; cin >> no; ) void spow() college: :show() ; a cout << “Number of employses. ) : di class nonteaching : public college t private: int no; int holi; public: void read() no of employees : “; cin >> no; holidays : * << holi; i show{) ¢ Number of employees : * << no. << endl; ‘cout << “Number of holidays : “ << holi << endl; '' a Pa class ce : public teaching { private: char desg[20]; ., _ char exp[20]; ie: void read() publ. { teaching: :read({); : cout << “Enter designation: “; cin >> desg; cout << “Enter experiance : “; cin >> exp; } NICE, V.V.Nagar - Ph. (02692)238534void show() { teaching: :show(); . cout << “Designation : ‘<< desg<
> dessa; } void show() { teaching: :show() ; oe cout << “Designation : ’ << desg <<.endl; y Ve void main() { ec obj obj.read() 7 1 obj. show() 7// Program 9 . // Program of hybrid inheritance #include
#include
class grandfather % | private: grandfather() {¢r=0;} grandfather(long d) {gr=d;)} void show(} : cout << “Grandfather : * << gF << endl; } he . class unclel : public grandfather { s “private: long ulr; aww ~) gather (a) void show() { : cout << “Uncle 2: “ << u2r << endl; ' - grandfather: :show() ; +) i class grandson : public unclel, public uncle2 who public: . grandson () {} 1 grandson(long 11, long 12, long 13) : unclé2(12),'unclet (13, 11) 0 : : NICE, V.V.Nagar - Ph. (02692)238534 woe noOR . NICvoid show() { unclel :: show(); uncle2 :: show(); } ye void main() { elrser(); grandson g(1000,2000, 3000) ; Grandfather : 3000 g.show(); getch(); - } // Program 1 // Pointer basics #include
void main() { int a=5,b=10; z cout <<.a << “ is stored at cout << b << ” is stored at * << &b << int *p; Se 4 p=ha; : cout << “p= “<< p << endl; cout << #p << endl; p=&b; ah cout << “ls is stored at OxBfceftia 10 is stored at OxBfc8ff£2 lp = Ox8£c8fff4 . 4p = 5 Ip = Ox8f£c8fff2 *p = 10 // arithmetic operate #include
void main() . { ee int a=5,b=10,c,*p; cout << a << “ is stored at “ << &a << endl; ‘cout << b << “ is stored at * << &b << endl; ' OUTPUT 5 is stored at 0x8fc8ffi4 10 is stored at Ox8£c8fft2 prkai (*p) +47 cout << “a << a << endl; p2&b; (Ap) +t . cout << “b= “ << b << endl;<< *p << endl; a ae ah ’ \ int, int); b=10; ~ “Before Calling Function : a="
. + void main() : { . void swap({int*, int*: int a=5;b=10 Before Calling Function : a="
- class Base € ‘ i public: void show() { cout << “I am Base Class\n"; , ye class Dervi : public Base C public: void show() { cout << “I-am Dervi Class\n"; } NICE, V.V.Nagar - Ph. (02692)238534 |e MODULE - 5.5 : virtual & friend Function/Class and thie Pojntervi class Derv2 : public Base { public: void show() { cout << “I am Derv2 Class\n"; } Me 3 void main() : . ¢ Dervi dl; Derv2 a2; Base *b; based; b-sshow() be8d2; be>show() ; OUTPUT I am Dervi Class I am Derv2 Class } //> Program 2 be, // Example of virtual function #include
: class Base { publi virtual void show(): Ses scout <<#] e 2 public Base amBase Class\n"; Bee class Dery, { publica, void show() ae cout << “I'am Dervl Class\n"; } vi class Derv2 : public Base t - public: void show() . C cout << “I am Derv2 Class\n"; } ue void main() { NIGE, V.V.Nagar - Ph. (02692)238534 237Dervl di; Derv2 d2; Base *b; b=8d1; It am Dervi Class b->show() ; It am Derv2 Class b=6d2; b->show(); \ : oe "7 program 3 oe // Example of pure virtual function #include
class Base virtual void show()=0; Mi class Dervl : public Base { public: . » void show() { tf Program 4 ‘/, Example of polymophism Hinclude
lass shape { public: ICE, V.VNagar- Ph. (02692)238534 . " 3virtual void read()=0; virtual void show()=0; vi . ‘ class circle : public shape { private: float x7 _ public: . void read() ie cout << “Enter radius : “; cin >> x; } void show() ( cout << “Area of circle } ae * ye *'r << endl; class rectangle : public shape { private: float 1,b; public: void read() _ cout << “Area of rectangle =" << 1*b << endl; class triangle : public shape af m private: float b,h; public: void read() an cout << “Enter base of triangle: “; cin >> cout << fener height of triangle : *;- cin >> h;cout << “Area of triangle = “ << bth*0.5 << éndl; } i void main() { shape *s[10]; int count=0, i, choice,menu() ; choicesmenu () ; , while (choice! =4) }; switch (choice) ee { case 1: classy s (count ]=new circle; { s[count]->read() ; 5, count++; a class.L break; Circle . { case 2: : Rectangle ~ Rp s [count] =new rectangle; s{count] ->read() ; count++; break; Enter radius : 10 case 3: ee 1: Circle s(count]=new triangle; 2: Rectangle s{count ]->read() ; 3.3 Triangle count++;, Exit break; ter Your Choice : 2 ad default: Enter Length of rectangle : void me “cout, << “mn 10 { 5 Enter Breadth of rectangle x : 20 : 1: Circle 3 2: Rectangle wh 3: Triangle : Sli]->shout); a: Exit Tease * } “ Enter Your Choice : 3 | includ int menu() Enter base of triangle : 19 | B*inclve t Enter height of triangle :* t int ch; 5. : pm cout << “1 : Circle\n"; 1+ Circle cout << “2 : Rectangle\n"; 2: Rectangle . cout << “3 : Priangle\n*; 3: Triangle cout << “4: Bxit\n"; 4: Exit cout << “Enter Your Choice : * | Enter Your Choice :4 ; cin >> ch; Area of circle = 314 class? return ch, ' Area of rectangle ee } Area of triangl );// Program 5 coe 7/ ambiguity in multiple inheritance ve // This program will not run, watch the errors carefu #include
Lot class Levell . ; { 4 public: ces int x; a .¢lass Level21-: public Levell { Ve : class Level22 : public Levell { Lone ve class Level3 : public Level21, public L { public: void set (int d) ft ~ xed; // Erro: i} void show () ti void main() { Level3 obj obj se (U /* Program . ren base class */" #include
class Levell . { public: oe int x; . a class Level21 : virtual public Level1 vi class Level22 : virtual public Levell 4rel3 : public Level21, public Level22 olic: a] void set (int d) { xed; } void show() { cout << x << endl; } de void main() { Level3 obj; obj. set (12); obj .show(); d // Program 7 ¢/ friend function #include
class B; ' class A ( private: int x; public: AY) Seki ‘friend void frifun(a,B); a ae class B ‘ private: int y; public: B() y=5; friend void frifun(A,B); d; : “void frifun(A obj1, B obj2) ° € cout << objl.x + obj2.y << endl; > NICE, V.MNagar- Ph. (02692)238534 avoid main() { A object1; B object2; frifun(objecti, object2) ; } // Program 8 // friend and operator overloading at // 2 = 10.5 + BL cine #include
5 class Height { private: int feet; float inches; public: Height () { feet=inches=0; { : . . cout << “Féet = “ << feet << “\tInches = “ << inches << endl; Height temp; — temp.feet = Hi.feet + h2.feet; aa temp.inches = hl.inches + h2.inches;" if (temp -inches>=12) ore { temp. inches-=12; temp. feet++; xeturn temp; oes 4 ; !void main() t- - Height H1(5,10) ,H2; } // Program 9 % //, fzdend as functional notation © = © se hs 7] a2=square(d1); use #include
. oe class Data ° t private: a int d; public: ~ Data() d=0; . } Data (int dt) { deat; 3 i void show() { . Fs ae couti<< d'<< endl; 9) . ve y friend Data square (Data obj) ; as ~ Data temp; temp.d = obj.d * obj.d; return temp; } ¢ de void main () fet { Data d1(12) ,d2; d2=square (d1) ; d2.show() 7 uw Program 10 '/ this pointer include
lass Data { private: ras int a; ee ew SE, V.V.Nagar - Ph. (02692)238534float b; : » char ¢; public: void show() . cout << this << endl; } uv void main() { Data t1,t2; tl.show(); t2.show() 7 y, : pheenns /* Program 1 . % simple File Progr seat i disk.*/ QUTPUT - #include
Rfter running this. program, void main() am to write a line of { ofstream obj (“NICE.TXT") obj << “NICE makes good c } 7]. Program 2 // Simple File Program to re #include
void main() { 7 sfstream obj (NICE. TRI"); char’ str [80]; while (obj) ad contents of a file on disk. ped Co: obj .getline(str, 80) + cout << str << endl; } : } // Program 3 ‘/] Weite into file sentence by sentence. #include
#include
Gher running this program,’ the'contents of the void main() file WELCOME.TAT should be’ + . { welcome to the world of programming ofstream obj (“WELCOME.TXT") 7 char str[80}="Welcome to the wor. 1d.of-progxanming at NICE": NIGE, V.V.Nagar - Ph. (02692)238534for(int i=0; i
' #include
void main() { ifstream obj (“WELCOME. TXT“) ; char ¢; while (obj) { obj .get (c); cout << cz + } // Program 5 #include
#include
class student student (int r, char n[20]) Sottnoee; . strepy (name, n) ; } : oe void set (int r,char n[20]) { rollno=r; 6 strepy (name,n) z . t void read() . foe C cout << “Enter rollno : *; cin >> rolino; NICE, V.V.Nagar - Ph. (02692)238534cout << “Entex name : “; cin >> name; } void show() . we + { : : cout << “Rolino : “ << rolino << endl; cout << “Name : “ << name << endl; } uM void main() { student s1(23,”Anang") ; student s2;s3,temp; s2.set (45,"Sachin”); s3.read(); ofstream obj1{“NICESTUD. TXT") ; obj .write( (char*)&s1,sizeof (s1) ), obji.write((char*) &82, sizeof (s2)},; obj.write( (char*) &s3, sizeof (s3)) objl.close(); Enter rolino : 77 Enter name Bhagirath tf obj2.xead( (char*) stenp temp.show(); 2 of obj2.read ( (char*)&temp, // Acces: ping #include
> num; pos=(num-1) *sizeof (student) ; . 7 // Program 7 // Command Line .Argument’ #include
void main(int argc, char *argv(]): for(int i=0; i
mycopy if vem (ch); NICE. TXT DES?.TXT hi d NICE, V.V.Nagar - Ph. (02682)238804_ /* Program 9 . Store ten integer numbers in a file DATA. Read'DATA file and separate the odd and even numbers out of ten numbers and then store all odd numbers in ODD file and even- numbers in , EVEN file. Write a program which provides above facilities. */ #include
void main() { int i,num; ofstream ofs (“DATA”); for (is1; i<=10; ++i) { cout << “Enter number + "3 cin >> num; ofs.write ((char*) énum, sizeof (int) ); } ofs.close(); ifstream ifs ("DATA"); ofstream ofs1(*EVEN”) ; ofstream ofs2(“ODD"); for (i=1; i<=10; ++i) ifs.read((char*) enum, sizeof (int)) ; if(num’2==0) ofs1.write((char*)&num, sizeof (int)); else ofs2.write((char*) enum, sizeof (int)); ! } ifs.close(); ofs1.close(); ofs2.close(); cout << “\nContents* of DATA” << endl; ifstream if81 ("DATA") ; while (ifst)” { . ifs1.read ((char*) &num, sizeof (int) ); cout << num << Neg ifs1.close(); cout << “\nContents of EVEN” << endl; ifstream ifs2 (“EVEN”); while (ifs2) { ifs2.read((char*) &num, sizeof (int) ); cout << num << “\t"; wee d ifs2.close(); cout << “\nContents of ODD” << endl; ifstream ifs3 (“ODD”); hile(ifs3) { HCE, V.V.Nagar - Ph. (02692)238534 “249 ————ifs3 .read((char*) &num, sizeof (int) ) ; cout << num << “\t"; d ifs3.close(); // Program 1 // Exception #include
#include
void main() { : a) . MODULE - 6 : Exception Handling & Template int a; cout<<“Enter the value of a(less than 100) :";:. try OUTPUT { ter the value of a(less than 100) :°59 cin>>a; value entered 59:is-less than 100-4nd is correct | | i£(a>100) - —— — A throw a; + catch(int x) { cout<<"The value entered “<
class simple { public: wk int min(int a, int-b) {return (a
template
tT min(T a, TD) {return (a
Idefine size 5 fot cemplate
cp ass roid display (T alsize]) 4 {for(int i=0; i
define max 5 late
s stack a : private: . 0-3 ‘Type st (max) ; Ans. int top; cl, K() {top=-1;} id m “ish (Type var) {st [++top]=var;} ‘ ne ‘) (return st [top-];} chi if o-4 © Ans! 0); sl.push (30.30); 1 ifstream\ o ofstream o? while (ifs) $ \ SE, V-V.Nagar - Ph. (02682,Exam Oriented IMP Questions & Answers j-1 Define flowchart and discuss the symbols used to draw'a flowchart. ins. A flowchart.is a pictorial representation of algorithm. As it represents Solution in form of picture, it is more easier to understand and Gevelop. A main advantage of flowchart js visibility of paths within Solution. Bach path is clearly visible as arrows are used to represent flow. Cc) start/Stop [=D subroutine & Continue | Input/Output ts Arrow Decision 1 v making [7] Process & Page break’. = y-2 what 4a algorithm ? Explain the importance of it in problem solving. gas. an algorithm. is a stepwise solution to 4 problems, Zach step in an algorithm represents a solution to a smali. problemsHence, algorithm gives a sequence of steps which makes complete solution of @ problem in and. An algorithm itself is ‘decomposition of probléin into'small steps which are easily understandable. et Gxauple 1 Write an algorithm to find area of circle. | Algorithm : 1. Input R 2. Compute A= 3.14 *R*R . 3. Print A 4 4. STOP . 0-3 Difference between flowchart & algorithm. Ans. Flowchart . Algorithm i. A flowchart is 2 pictorial 1 An algorithm is.a stepwise representation of algorithm. solution to a problem. At is represents solution 2. As is represents solution in form of picture. in form of statement. . 3, 6 Main advantage of flowchart 3. Advantage of algorithm . js visibility of paths gives a sequence of steps within solution. which makes complete solution explain in detail with example. of a problem in hand. 1, Assembly, Language . 2. Machine Language - 3. ° High Level Language ans. le Assembly Language + whe fivst step in the evolution of programming Languages Woe the development wee what ig known as an assenbly language. In assembly ‘language, mnemonics are used to represent operation codes, and strings’ of characters to tepresent address, As an assembly language is designed mainly to replace coer machine code with an understandable mnemonic ‘and each alphanumeric , String. It is matched to a particular computer’s processor structures. Lig machine dependent. It is necessary for an assembly language programmer to know all details of a computer's Jogical structure in Peder to write a program. The assembler is a system program which is Gapplied by the computer manufacturer, 1t is written by system programmers with great care | NICE, V.V.Nagar - Ph. (02692)288534 2533. 0.5 je ‘asy to write . difficult. yp erpreters do not requiere much * Compilers requiore large NI [vantages = [1] Programming is the efficiency of the machine language progras xesulting from it, [2] All hardware features available in the processor of the computes like registers, stacks etc. . (3] Great flexibility in writing programs well matched to the computer, Disadvantages 3 : (1] It is machine-dependent it is not portable from one machine another. “a , (21 Programmer must be an expert who knows all about the logical structure of the computer. _ ae: [3] Writing assembly language programs is difficult and time consuming, | Machine Language : : id Machine language is the only proyramning language that the computer cd understand. It is a language made up entirely of 1s‘and 0s. There ds| not, however, one universal machine language. The arrangement of 18 and Os to represent similar instructions, data and memory locations differs among computers because of different hardware designs. Programmer should] have detailed knowledge of how the machine works. It is easy to make ah error and very difficult to debug the-inachiné language program. 4 Advantages : . 3 (1] Programs have an advantage of very fast execution speeds. [2] _ Efficient use of primary memory. ne Disadvantages + ge Jed gS? (1] This language is very'tedious, difficult-and time consuming method of programming. — —_— ; (2] Machine dependent... z ‘ High-level Language. ee . High-level language are language whose instructions closély resemble human language and mathematical notation. High-level language do not xequire that the programmer have'detailed knowledge about the internal operations of a computer. High-level language are also much easier to learn and use.than either machine or assembly language before they cas] be used by a computer. One of the two different translator programs is used to: translate high-level language an interpreter or a compiler. An interpreter is atranslator which translates a Program into machine: language one line at.a time and executes line of the program after it is translated. A compiler translates a whole program at once into} machine language and then it can be immediately executed any time thereafter. Advantage : . - (i) ft is easier, to learn and use then either machine or assembly) language. 4 [2] Programming errors are easier to avoid and correct. Define interpreter * compiler & give the difference between then. A compiler is a translator that takes a complete source program; translates and gives out the complete machine language progran. When the compilation is over the machine language program is available and the computer can execute the program. While an interpreter takes the source Program one line at a time translates that line executes it and then takes up the next line. Here the complete object program is not ready for execution’ : Interpreter Compiler . Interpreters are simple and * Compiler’s are complex and Sg ory space in the computer. memory space in the computer, | af wes Nagar - Ph, (02692238534 254 i IS :ter or. to wee eree * Interpreters take less time * Compilers require less time to translate. to execute the same program in the computer * . Interpreters translate sentence ® Compilérs translate the whole by sentence. program. Q.6 Write short note on generation of computer language Ans. Generation of computer language + ist Generation + Period : 1950 - 1958 Example Languages : For'ran 1, Flow Matic (Data Processing), IPLS (List Processing) . : Syntax : Statements, expressions, DO Loops, GOTO In, if, label, routine etc. were introduces in ForTran 1. Technology : Bottom- up. design : Hardware dictates language design Storage Allocation ; Static(i.e. size of variable was reserved.” + 2nd Generation : Period : 1957 -1961 2 . Example Languages: ALGOL 60(1957-1960), COBOL (Commion' Business oriented Language (1959-1961) COBOL was business Oriented and was divided into two division : it wa machine independent LISP (List Processing) (1959-1961). Tt.was an applicatio ‘language designed for nonnuneric processing. Used wide ‘inaxtificatal Intelligenc (ar satan recursion, concept of nexted block structure explicit type declaration for variables, call by value parameters. It - then-else, for loop, whildloop, switch; xeal/boolean) . Technology : Top-down. Storage Allocation : Dynamic. rule of variables passing procedur ee data-types (int Period : 1960 -1970 Example Languages: PL-I, ALGOL 60, Pascal; "SIMULA 69,. BASIC C. PL-I + It combined important concepts of Fortran, Pascal, COBOL. It is genera’ purpose to satisfy-for commercial areas, system programmers and scientific needs ALGOL 60 : Served as Basic for ALGoL. W,. ALGOL 86, Pascal, It removed use of label: as parameters of: procedures. SIMULA 69 + Process: oriented language, Concept of Class and Subrutines. . APL : Mathematics. Application # 4th Generation : Period ; After “1970 ' Most 4GL’s were evaluated from Pascal. toe Example Languages: CLU, ALPHARD, EUCUDS, MODULA,ADA. Main features of these languages was modularity by means of abstraction-hidin details from users. * Modular: Language for modular multiprogranming. ADA: General Purpose Language. Q.7 Write comment on: C is a middle level lanquage. Ans. - The different categories of lanuages are s.ometimes labeled by generation: -from lowest to highest. - Machine lahguages are considered first generation. ‘(1950 '-1958) - Assembly languages are second generation. (1957 -1961) - High level languages are third generation. (1960-1970) Fourth-generation (After 1970) It is a term that-describes a variety of programmin languages that allow: user to create programs with much less effort than is required by higt level languages. © languages was developed by Dennis Ritchie.in 1972 at, Bell telephone NICE, V.V.Nagar - Ph, (02692)238534 ~ 255Laboratories in USA, So C is middle level language. @ehas been defined so that it has the advantages of a high level language, nanely, machine independence. C was to write an operating system known as unix. ~ -¢ is highly portable . (C programs written for one computer can be run on another) * - Program written in ¢ are afficient and fast. . - The C compiler combines the capabilities of an assembly language with the features of high level language and therefore it is well suited for writing - both system software and business package. Q.8 How many types of error & What types of errors can be & can be not detected by compiler ? Ans. C compiler has number of common errors. All errors can be classified under four types. = syntax error Any violation of rules of the language results in syntax errors. - run-time errors : Error such as mismatch of data types or referencing an out~of-range arragy element go undetected by the compiler. A program with these mistake will run, but produce erroneous result. + - Logical errors . 2 & 7 As the name implies, these errors are related to.the logic of the program excution. Logical er'ror.do not show up ag.compiler generated error messages. Rather, they cause incorrect result. ' - latent errors BFE - : It is a hidden error that show up only when a particular set of data is used. . ‘ . Qf" Describe in brief operators give the heirarchy of all operators. + The operators are used to perform various operations on the data or operands. The C languages is rich in the terms of operators it supports. We will study the use of various types of operators like. +..... --> ARITHMETIC OPERATORS . C provides all the basic arithmetic operators. Operators Substraction or unary minus Multiplication Division / & --> RELATIONAL OPERATORS We often compare two quantitives and depending on their relation, take certain decisions for example, we may compare the age of two persons, or the price of two items, and so on these comparasions can be done with the help of relational operators ye have already used the symbol‘<; meaning’ less than is less than is less than or equal to is greater than is greater than or equal to is equal to is not equal to -> LOGICAL OPERATORS In addition to the relational operators © has the following three ICE, V.V.Nagar - Ph, (02692)238534 256> that nce. logical operators . . Operators Meaning ge Meaning logical AND + tH Meaning logical OR with ! Meaning logi . d for aren ene The logical operators && and |! are used when we want to test-more than one condition and make decision. --> ASSIGNMENT OPERATORS Addl gnment. operatord are wuied to auulgn the result ef an exprenulol Lo a variable we have seen the usual assignment operators, ‘=In addition C has a set of shorthand’ assignment operators of the form . Statement with simple Statement with lange ese | » ' the : a= a/ (n=1) 1% ated arate i ~-> INCREMENT AND DECREMENT OPERATORS o lata © has two very useful operators not generally: fo n other languages. ‘These are the increment and decrement operators. ° ++ And ~~ ca as. : Ady : ~-> CONDITIONAL OPERATORS : A ternary operator “?” is available in C to conditional expressions of the form (expl) ? ex2 : exp3; expl is evaluated first. If it is true, then the expression exp2 is evaluated and becomer the valuer of the expression. If exp 1 is false, exp3 is evaluated and its value becomes the value of the expression. ‘ ~-> BITWISE OPERATORS : C has a distinction of supporting special operators known as bitwise operators for manipulation of data at bit level. : operators : Meaning : & Bitise AND . 1 Bitwise oR * Bitwise exclusive OR << shift left > shift right ~ One’s complement --> SPECIAL OPERATORS C supports some special operators of interest such as comma operators, size a NICE, V.V.Nagar - Ph, (02692)238534 257os ( of operator, operator operators (& and *) and menber selecti+: sperat and ->). Comma Operator + Whe comma operator can be used to link related expressions teqetler. Jalue = (x= 10, y = 5, xylem); The size of operator : The sizeof operator is a compile time operator and, when and with ay operand, it returns the number of bytes the operand occupies. ‘The operand may be a variable, a constant or a data type qualifier. Ans + Examples : m= size of (sum); m= size of (long into); ‘ m= size of (235); Q.10 Describe 1/0 statements. Ans. Input Statement Formed input refers to an input data that has been arranged in a particular format. For example, consider the following data : 15.75 123 John Qhis line contains three pieces of data, arranged in a particular form Such data has to be read conforming to the fornat of its appearance. For} example, the first part of the data should be read into a variable float. The second into int. and the third par into char. This is possible in C usizig the scanf function. We have already used this input function in a nunber of examples. Here, we shall explore all of the options that are available for reading the, formatted] data with scanf function. The general form of scanf is Seanf (“control string”, argi, arg?, ......., arom); Output Statement ; We have seen the use of printf funciton for printing captions and numerical] results. It is highly desirable that the outputs are produced im such a way that they are understandable and are in an easy to-use form. It'is thereford necessary for the programmer to give careful: consideration to the appearance and clarity of the output produced by his progran. | His printf statement provides certain features that can he effectively exploited to control the alignment and spacing of print-outs on the terminals. The general form of printf statement is prinf ("control string", argl, arg? ...... argn) Describe data type inc. , fs. C language is rich in its data types. The variety of data types available allow the programmer to select the type appropriate to the needs of the application as well as the machine. ANSI C supports four classes of data| types. wee Orimary data types -> user-defined data types -> Derived data types -> Empty data set All C compilers support four f-indamental data types, namely integer (int), character (char), floating point (float), and double precision floating| point (double). Many of them also offer extended data types such as long int) and long double. Size and Range of Basic data types. Q.1 Ans a1! Data type Range of values | ; char -128 to 127 int ~32768 to 32768 float 3,de-38 to 3.46438 1, 7e-308 to 1.7¢+308Q.12 Define : expression, briefly describe the different types of expression with oxamples Ans. Arithmatic expression consists of operators, constants and variables. The mathematical formulas can not be directly written in programs. ‘It requires aie conversion of formulas into expressions which follows -the syntactical yules of the language. The operators to be used must be supported by the language. an ‘he C does not support the expotential operator which requires x? to be may written in C as X**X, For example the formula. Jab 1 is written in C as orl Stet) : (2*atb) / (c+1) ~ 1/(3* (pea) ) An arithmatic expression without parentheses will be evaluated from left to right using the rules of precedence of operators. There are two distinct, priority levels of arithmatic operators in C. jar High priority +78 Low priority + Q.13 What symbols terminates every C statement.
12345, ~54321, 10, 786 ete. => Integer _ + => 10.83, -0,25, 235.55 ete. cnavact2®e stant . aracter constants : => 11h, (KY, 1K, ete. , ~> Single character > "NICE", "IN", “india”, «N*, 45", etc. -> string NIGE, V.VNagar-Ph. (02692)230534 259 ———— poi”#include
#include
main() { elrser(}; : g. 700000 printé (*#d\n",5); printf (*%£\n",6.7); firce_bay printf (*c\n",’a’); printf (*%s\n", "NICE DAY") ; getch(); ) What do you mean by problem analysis 7. The first step in developing a program is to understand the problem for which program is to be developed. Unless until program is not clearly understood, program can not be developed or it may be developed incorrectly, The aize and complexity of problem are two major factors which needs to be considered while understanding a problem and developing a solution to it. In problem analysis, given problem which is very difficult to understand ag single piece is divided into sub problems, each. sud problem then can be further divided into smaller problems. This process is'repeated until, yoo get a set of sub problems which are small, ‘easy to understand and manage: After developing solution to eagh small problem, integrating their solution properly gives total solution. Difference between “-” operator & “==” operator. The single equal sign meaiis“assignment, where the double equal sign isa relational operator used for testing purposes. What is variable ? ~ It is symbolic name for a memory location in which the value is ‘stored. Write a ¢ program to check whether given number is palindrom or not ? #includéxstdio. hy void main() { long int num, sum=0, temp; printf ("Enter a number :*); scanf(*81d", &num); temp=num; while (num>9) t 121 sum = sum* 10 + num %10; Number is palindrom num = num/10; } printf (“reverse = %1d”, sum); if (sum=-temp) { printf (“Number is palindrom* , “{ print (*Number is not palindrom"); } } Write a ¢ program to check whether given number ig armstrong or not ? tHinclude
void main() { int num, sum=0, temp; NICE, V.V.Nagar - Ph. (02692)238534i print£(*Enter a number :*); scanf (*%1d", num); temp=num; while (num>0) sum = sume ( (rium&10 (numt10)) 7 [ num = num/10; i } d j | seisumestono) [eae { 4 ” wy 153 ' d : else i { : t print (4Not Armstrong”); ] ) : ‘ t } 9.23 Distinguish betwe hus. Global variable : Global variable can be accessed and modified by any function with also known as external variables. : Scope : Whole program hifetime : Until the termination of program. - Local Variable : Local variables are defined within a function, and can b aecessed by the function only in which they axe defined, i.e., private t the function is called and destroyed ‘automatically when the function exited, hence called automatic variable. Scope = function in which they are declared. Lifetime : Until the termination of the function. (9.24 Difference between break & continue. sas. “break” statement terminated the execu! oo of loop, in which it reside: ir control comes to the statement: imnediately after the loop. “continu statement transfer the-control to the beginning of loop, with next value variable, The statement within the loop after continue, will not be execute 9.25 Explain switch statement explain how dt differs from the if statement ? srg. Logically each program written using if ‘statement, can be implemented usi tettch statement, and vice versa. But in if statement, when number eiternatives or increases, the program increase dramatically. The progr becomes difficult to read and follow. Use of switch makes program easy read, write and understand. ° 9.26 Differenciate clearly with while statement. ‘Ans. A do while loop makes th ‘loop performs its test before Example of do....while loop. Suppose, To print 1 to 10 in one line using do while loop.! * Pinclude
main() = : € int i=l; . do . en local variable & global variable 2 are defined outeide @ function, and th in the’program. They ar proper example(s) do..---- while statement e test after the body is executed. Whereas whi the body of. loop is executed. NICE, V.V.Nagar- Ph. (02692)238534ne { . print£("%d", i); isitl; watle(i<20); Juppose, To print 1 to 10 in one line using while loop #include
nain() ( int isl; while (i<=10); ¢ printé (*8d", i); isis; ; + What is structure give it advantage over the array how a two dimensional | array can be. initialised during declaration ? Ans. An array is'a group of related data items having same data types, which share a common name, Where as structures is methéd of packing logically related data items having different data types. Before any element of any array can be used, it must have a value, initializing an array gives a value to each of its elements. We can also initialize a two-dimensional array in the form of matrix as shown bellow. int table(2] [3]=((0,0,0)(1,1,1)); ' Note the syntax of the above statements, commas are required after each brace that close of a row, except in the case of the last row. If the values are missing in an initializer, they are automatically set to zero, for instance, the statement. Q.28 Give any three functions used for string manipulation by giving suitable example. . ans. (1) etrlen() : This function is used for finding out length of string. The string in question is passed as argument to this function and this function returns the length of the string in integer. For example int=strien(*Hello"); After execution of this statement n will have 5 (Length of “Hello”). (2) stropy() : This function is used for copying one string to other. The format is strepy(dest, source), where dest and source both are string variables. The content of source string is copied into dest string. Tf before execution of statement, dest contains some value (string constant) the previous value will be overwrite by the new value (specified by source string). For example : char source[]= ‘Hello*, dest (J= “dummy”, stropy (dest, source); Now dest will have content “Hello”, . (3) stremp() : This function is used for comparing two strings. The two strings to be compared are pasdéd as arguments to this function, and function returns 0 if both the strings are equal, positive if first string is greater than the second string-or negative if the first string is smaller than second string. For case insensitive comparision stremp() function is used, Here “i* stands for Insensitive comparision. . What is the purpose of initializing an arrey ? Before any element of an array can be used, it must have a value, initializing an array gives a value to each of its elements. (0 what is array ? Write the advantages & disadvantages of it ?. Aus. An array is group of eleménts-having game data type sharing common name. To understand the need of array variable,"let’s take an example, suppose I want to write a program to add three student's marks. I can use three NICE, V.V.Nagar 262 9.32 Ans:i | Q.32 af | ans | a h ry | r | i 0.32 Ans. ee @ifferent variables, for example marks, marks2, marks3. But if extend the same program for 100 student, partically. What is structure ? how to declare structure ? How the elements of structur can be accessed ? How is it different from union ? Write your ansyer b talking suitable example. An array is group of elements having same data type sharing common name, constructed data type known as structure, which is method for packing dat of different type. Structure help to organize complex data in a mor meaningful way. It is a powerful concept that we may often need to use i our program design. Book database consisting of book name, author, number of pages and price. W can define a structure to hold this infornation as follows : struct book_bank C char title (20); char author [15 int pages; float price; book_bank is the nane of structure and is called the structure tag and it is used for a declare a variable that have the tag’s structure. the keywore struct declare a structure to hold.the details ‘of four fields, like, title, author, pages and price. These fields are call structure’elenents or members. Each member may belong to a different type of data. We can declare structure variable using the tag name anywhere in program. Normally structure and union is same but unions are a concept borrowed from structures and therefore follow the same syntax as structures. There is major distinction between them in terms of storage, In structures each member nas its own storage location. Where all the meribers of a union use the same location. It can handle one one member at a time. Union can declared using the keyword union as follows : union item int m; float x; char ¢; jeode; What is mean by recursion ? explain with example. Function call itself that is recursion, recursion fs the special case of this process, where a function calls itself, recursive function can be effectively used to solve problems where thé solution is expressed in terms of successively applying the same solution to subsets of the problem. When we write recursive function, we must have an if statement. Somewhere to force the function to return without the recursive ‘call being executed. Otherwise the function will never return. . Explain : 1) faeek() 2) ftell() 1) feeek() = fseek function is used to move the file position to a desired location within the file. It takes the following form, fseek (file ptr, offset, position); file ptr is a pointer to the file concern, offset is.a number or variable of type long, and position is an integer number. The offset specifies the number of positions to be moved from the location specified by the position, The position can take one of the following three values. Val Me 0 Begining of file : . 1 . Current position . V.V.Nagar - Ph. (02692)238534- 2632 End of file * 2) ftell() + ftell takes a file pointer and returns a number of type long, that correspon the current position. Q.34 What is variable ? What are the rules for naming variables ? Give ndne examples of valid & invalid variable name. Ans. A variable is a data name that may be used to store a data value. A variable name can be chosen by the programmer in a meaningful way so as to reflect [W ‘ its function or natures in the program. some examples of such name are; fB? wo 1) Average 4) counter_i 2) Hieght 5) class_strength 3) Total As mentioned earlier, variable names may consist of letters, digits, and the underscore(_) character, subject to the following conditions : Rules for naming variable. 1) ‘They must begin with a letter. Bi 2) Length of 31 characters. =: 3) Uppercase and lowercase are significant.” 4) ‘The variable name should not be a keyword. 5) White space is not allowec le. F valid / Invalid ali : 5 Not valid char isa keyword ‘ Not valid Dollar sign is illegal Not valid Blank space is not permitted i nice_is_nice valia Explain in brief for statement. The general form of the for loop is for (initialization ; test-condition ; increment/decrement) t body of the loop i + The first expression (initialization statement] is executed once. The second expression (condition) is tested, it is evaluated true, the body of the loop I is executed. Then the third(modifier) expression is executed. Once again t second expression (condition) is evaluated. As long as the second expression is true, the body of the loop is executed followed by the third(moodifier) :, expression. When the second statement (condition) evaluated as false, the loop terminates. ‘The initialization, testing and modifier expressions of the loop all are ecified within a single set of parentheses. xplain in brief while statement. The basic format of the while statement is . . while (condition) S { qi body of the loop } The while is an entry controlled loop statement. The condition is evaluated and if the condition is true, then the body of the loop is executed. After execution of the body, the condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the condition finally becomes false and the control i is transferred out of the loop. On exit the program continues with the I my_nice Valid i i NICE, V.V.Nagar - Ph. (02692)238534 264 adifferent variables, for example marks1, marks2, marks3. But if extend the same program for 100 student, partically. | 9.31 what is structure ? how to declare structure ? How the elements of structure z can be accessed ? How is it different from union ? Write your ansyer by talking suitable example. An array is group of elements having same data type sharing common name, < constructed data type known as structure, which is method for packing date of different type. Structure help to organize complex data in a more meaningful way. [t is a powerful concept that we may often need to use ir our program design. Book database consisting.of book name, author, number of pages and price. we can define a structure to hold this infornation as follows : struct book_bank { char title[201; char author [18]; . int pages; float price; book_bank is the name of structure and is called the structure tag and it is used for a declare a variable that have the tag’s structure. the keyword struct declare a structure to hold the details of four fields, like, title, author, pages and price. These fields are call structure'elements or members. Each member may belong to a different type of data. We can declare structure variable using the tag name anywhere in program. Normally structure and union is seme but unions are a concept borrowed fram structures and therefore follow the same syntax as structures. There is major distinction between them in terms of storage. In structures each membér has its own storage location. Where all the members of a union use the same location. It can handle one one member at a time. Union can declared using the keyword union as follows : union item C int m; Float x; char ¢; jeode; Q.32 What is mean by recursion ? explain with example. Ans. Function call itself that is recursion, recursion is the special case of this process, where a function calis itself, recursive function can be effectively used to solve problems where thé solution is expressed in terms of successively applying the same solution to subsets of the problem. When we write recursive function, we must have an if statement. Somewhere to force the function to return without the recursive ‘call being executed Otherwise: the function will never return. Explain : 1) faeek() 2) ftel1() 1) feeek() + fseek function is used to move the file position to a desired location within the file. It takes the following form, fseek (file ptr, offset, position); file ptr is a pointer to the file concern, offset is.a number or variable of type long, and position is an integer number. The offset specifies the number of positions to be moved from the location specified by the position. The position can take one of the following three values. Value Mean, 0 Begining of file 1 Current position NICE, V.V.Nagar - Ph. (02692)238534 2632 End of file . 2) ftell() : ftell takes a file pointer and returns a nunber of type long, that correspond ° the current position. x What is variable ? What are the rules for naming variables ? Give née examples of valid & invalid variable name. A variable is a data name that may be used to store a data value. A variable ¢ name can be chosen by the programmer in a meaningful way so as to reflect its function or natures in the program. some examples of such name are :' fe A 1) Average = 4), counter_i 2) Hieght 5) class_strength 3) Total As mentioned earlier, variable names may consist of letters, digits, and the underscore(_) character, subject to the following conditions : 1) ‘They must begin with a letter. ‘ 2) ‘Length of 31 characters. ? 3) Uppercase and lowercase are significant. 4) ‘The variable name should not be a keyword. 5) _ White space is not allowed, Not valid char is.a keyword ‘ Not valid Dollar sign is illegal " Not valid Blank space is not permitted my_nice Valid . nice_is_r nice valid Explain in brief for statement. ‘The general form of the for loop is for (initialization ; test-condition ; increment /decrement) C body of the loop } The first expression (initialization statement) is executed once. The second expression (condition) is tested, it is evaluated true, the body of the loop I is executed. Then the third(modifier) expression is executed. Once again second expression (condition) is evaluated. As long as the’ second expression is true, the body of the loop is executed followed by the third (moodi fier) | expression. when the second statement (condition) evaluated as false, the loop terminates. The initialization, testing and modifier expressions of the loop all are ecified within a single set of parentheses. : Qyy Bolaie in brief while statement. 7 The basic format of the while statement is _— while (condition) : { Gi body of the loop } The while is an entry controlled loop statement. The condition is evaluated and if the condition is true, then the body of the loop is executed. After execution of the body, the condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the condition finally becomes false and the control i is transferred out of the loop. On exit the program continues with the NICE, V.V.Nagar - Ph. (02692)238534 264serememnthnnserpenennnnerea statement immediately after the body of 1cop, due weapon 0:37 Explain the gifference between structure and Gnionh ames fas. The major aifference petween structure and win isjn texms orage. Ir ve name ceructure each menber has its own. storage location, 6 Fame per Sf a union use the sate Location: his implies? aieb6 EAuition may contais member at a time. many members of Ans, The general form of declarat: char city (101; gign a characte’ when the complier as: s automatically supplies 4 null characker ( ¢.38 How ds a string stor 2 ” fon of a strips yarighleds-| 9 wos: ghayacter array, 3 of bbe string. we can store string.--++.+* Like. +. 1141 char city[10}="V V NAGAR” Shar city (Lol=(Vir | fe Wie 15, wo 1 9.39 What is the union contructot 2 § —Tipmerdnbed senenees Cea ' Union and structure having sane syntax i storage. In structure! Qnreas all the members of union use the sal Geclared using the keyword unienze® address. like..++ 1288 BEE i union item { ans. int code; stted float price; char name [20] ‘p-4s0u0 Yi 9.40 Explain different type of Ans. zond Loop rain sion er) the are . . num ([2 float) aualSTit , ohar,game[10] + i When the compiler sees a character string, : ve character (‘\0'), 60 ve-muse-favnye P * the null terminator. ‘an array variable having t array. For example : suppose we three subject then we may fina 5 each membem Suis id baidotmpestaeadé boda ib sould x4 : biqmsxe 10% ngion 1 or sing jesus Tonall or, va Sp) Stabe: ma © Ant stai31(33s ae NICE, V.V.Nagar- Ph. (02692)238534 ————subi Sub2 stdi* +56 5656 note std “89 23 98 * sta3 75 69 89 two dimensional arrays are stored in memory as follows’: Col col Col 0 1 2 Tot etd[3] [3]; Columns Rows We represent a particular value in matrix by using two subscripts such as * Vij. Here V represent the entire matrix and Vij refers to the value in the ith row and jth column. ~ s, How to initialize in two-dimensional arrays }~,- int table(3][3] = (56, 56, 56, 89, 23,.98, 75, 69,99) or int table[3] [3] = (56, 56, 56), (89, 23 6 multi. An array variable having three of four- ox three dimensional variable afray, . “ For example + suppose we want. to-represent alset of two student marks in five subjects of three different class then we may declare the variable std as follows : Subl_/Sub2“ sub3 “Subd. -subs 89 (21(2) sta- ist Student, 2nd student! a9 {2] [a] std 2 | Z\X (21 (2)} (2) [2] ‘Columns 8s ag 89 89 312]/ (21 [21] (2) [21] (2) (2) as 89 89 a9 12] }f2) (aj (2) [21] (27 (23 1st Student, 2nd student} peo PDOal a d 4 Ans. 0.42 Ans. Q.43 Ans. felose(fp1) + How are command-line arguments accessed 7 It is a parameter supplied to program when the program is invoke. parameter may represent a ‘filename the program should process. Example : to copy the contents of a file from one file to another fil! C:\omycopy hello. txt bi. txt we in fact main can take two azgunents called arge and argv and thé informa contained in the command line is passed on to the program,through t! arguments, when main is called up by the system. oy Example : Suppose we want to make the our own copy ‘command. Write following program and compile then run above commar Pile name : mycopy.cpp cee : #incluecstdio.h> void main(int arge, char*argv’ t FILE *fpl, *fp2; 7 char ch; fps gopen(arg(1} x"); fp2=fopen(arg[2] ,“w") ; . while (ch=gete(fp1) !=EOF) . { pute (ch, fp2) ; } print£ (“my message : 1 file copied”); fclose(fp2); ~ . e + ) What is always the first string in argv? ‘Whe variable argc is an argument counter that counts the number of argu on the command line. The. argv is an arguments. The size of this array be equal to the value of that point to the command line given above, at three and argv is an array of three pointers to strings'as shown bel argv[0] mycopy argv(1] hello. txt ce . sob . argv(2] hi, txt The first parameter in the command line is always the program ni therefore argv[0] always represents the program name. . Write the advantages of using register reference in the program. A register access is much faster than a memory access:’Kééping the fr accessed variables in the register will lead to faster execution of pi This type of variable is declare as-follow. es register int count; ‘This type of variable is used in function or block ‘and its life is unt of function. . Under what circumstances a file is more useful than an array. A file is a place’on the disk where a group of related data is sto1 becomes cumbersome and time consuming to handle large volumes o| through terminals. Where array is limitation of store data. The entir is lost when either the program is terminated or the computer is turn¢ ‘Therefore necessary to have a more flexible approach where data | stored on thedisks and read whenever necessary. Without coin data. This method employes the concept of file to store data., Wher} array we can’t store data into disk. NICE, V.V.Nagar - Ph, (02692)238534© plana Sone lit as Yoomna "sen Ce or pe aeet eh CBR’ : (D poem ® rettematig Fs Ony n& Sciohiy UAT ok E . Sherman an® Aragon : QD wesopweeesos gull Her cromsbechuains, agp oBiens bY kochhow m& Buss @Dobucrviel PYOTY mt Blane, Te Reyter” oO 4 “3 Cllege pore Bese , a [eta Nevsawale | Qelly- 1 190% JT .bex022 ai 52. # s3sb lo 2emuloy opis | ald paivoties® tvodsiw .yisansxen ti ee ox9HW .638b 91052 oF lit Yo 3¢
You might also like
Data Structure Using C Lab
PDF
100% (2)
Data Structure Using C Lab
75 pages
C Programs
PDF
100% (1)
C Programs
10 pages
PST Programs
PDF
No ratings yet
PST Programs
14 pages
A Personal Collection of CODE (C++) Turbo++ Shamim Mahmud Nazmul Hosen
PDF
No ratings yet
A Personal Collection of CODE (C++) Turbo++ Shamim Mahmud Nazmul Hosen
30 pages
The Sum and Average of N Number of Marks of A Student
PDF
No ratings yet
The Sum and Average of N Number of Marks of A Student
28 pages
Portfolio Submission
PDF
No ratings yet
Portfolio Submission
47 pages
Programming in C: Unit - V File Processing
PDF
No ratings yet
Programming in C: Unit - V File Processing
12 pages
17
PDF
No ratings yet
17
35 pages
Print C Programme
PDF
No ratings yet
Print C Programme
41 pages
CSE2010 - Advanced C Programming Lab Assignment - 2: Name: Ajayjith.N.S Reg - no:18BCE2332
PDF
No ratings yet
CSE2010 - Advanced C Programming Lab Assignment - 2: Name: Ajayjith.N.S Reg - no:18BCE2332
11 pages
Module 5 Programs
PDF
No ratings yet
Module 5 Programs
8 pages
Adv C Slip Solution
PDF
No ratings yet
Adv C Slip Solution
31 pages
Name - Ayush Raj REG NO - 20BCT0168 SUBMISSION DATE - 27/02/2022
PDF
No ratings yet
Name - Ayush Raj REG NO - 20BCT0168 SUBMISSION DATE - 27/02/2022
19 pages
Annotated-C Assignment 202017b3723
PDF
No ratings yet
Annotated-C Assignment 202017b3723
27 pages
Theoryassign
PDF
No ratings yet
Theoryassign
15 pages
Structures in C
PDF
No ratings yet
Structures in C
6 pages
Source Code Final
PDF
No ratings yet
Source Code Final
27 pages
Document 1
PDF
No ratings yet
Document 1
19 pages
Digital Assignment - 4
PDF
No ratings yet
Digital Assignment - 4
13 pages
BX4002 - PSP Program
PDF
No ratings yet
BX4002 - PSP Program
31 pages
String Get - String
PDF
No ratings yet
String Get - String
17 pages
File Creation, Reading From and Writing To File:: CSE115L - Computing Concepts Lab Lab 15
PDF
No ratings yet
File Creation, Reading From and Writing To File:: CSE115L - Computing Concepts Lab Lab 15
2 pages
Pointer Print For Lab Record
PDF
No ratings yet
Pointer Print For Lab Record
11 pages
Exp No 1
PDF
No ratings yet
Exp No 1
23 pages
Operating System Lab (K)
PDF
No ratings yet
Operating System Lab (K)
67 pages
SRC 2
PDF
No ratings yet
SRC 2
32 pages
Set A C Program Solutions
PDF
No ratings yet
Set A C Program Solutions
13 pages
Write An Algorithm and Draw Corresponding Flowchart To Calculate The Factorial of A Given Number
PDF
No ratings yet
Write An Algorithm and Draw Corresponding Flowchart To Calculate The Factorial of A Given Number
33 pages
C Lab Manual
PDF
No ratings yet
C Lab Manual
16 pages
Ibcomca C Lab
PDF
No ratings yet
Ibcomca C Lab
14 pages
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
PDF
No ratings yet
Program To Read File Containing Rollno, Name, Marks of Three Subjects and Calculate Total Marks, Result in Grade and Store in File
9 pages
DocScan 11 08 2022
PDF
No ratings yet
DocScan 11 08 2022
17 pages
Record 11 To 14
PDF
No ratings yet
Record 11 To 14
13 pages
C File
PDF
No ratings yet
C File
37 pages
Background: Problems
PDF
No ratings yet
Background: Problems
31 pages
Share Lab Assignments On Pointers 13001618027
PDF
No ratings yet
Share Lab Assignments On Pointers 13001618027
6 pages
Cprogram Final Lab Manual
PDF
No ratings yet
Cprogram Final Lab Manual
26 pages
C Lab Record FINAL CS-IT-BCA To Print 2023 Batch
PDF
No ratings yet
C Lab Record FINAL CS-IT-BCA To Print 2023 Batch
41 pages
Partial Code
PDF
No ratings yet
Partial Code
14 pages
C Program Using Pointer
PDF
No ratings yet
C Program Using Pointer
9 pages
Sodapdf
PDF
No ratings yet
Sodapdf
23 pages
C Programming Practicals
PDF
No ratings yet
C Programming Practicals
34 pages
C Programming Notes - Part 2
PDF
No ratings yet
C Programming Notes - Part 2
16 pages
C Program Lab Manual
PDF
No ratings yet
C Program Lab Manual
24 pages
CPROG IA-3 Scheme Solutions
PDF
No ratings yet
CPROG IA-3 Scheme Solutions
7 pages
Lab 0-1
PDF
No ratings yet
Lab 0-1
15 pages
Files
PDF
No ratings yet
Files
5 pages
Pps Lab
PDF
No ratings yet
Pps Lab
14 pages
Compiler Lab Report, DIU
PDF
No ratings yet
Compiler Lab Report, DIU
13 pages
C Program LAB REPORT
PDF
No ratings yet
C Program LAB REPORT
8 pages
Final PGM
PDF
No ratings yet
Final PGM
34 pages
C Programming Loop
PDF
No ratings yet
C Programming Loop
14 pages
Codes of CTSD 2 (Mas)
PDF
No ratings yet
Codes of CTSD 2 (Mas)
17 pages
Computer System & Programming (Solutions)
PDF
No ratings yet
Computer System & Programming (Solutions)
9 pages
C Language Standard Questions
PDF
No ratings yet
C Language Standard Questions
26 pages
RBNMM
PDF
No ratings yet
RBNMM
2 pages
C Lab Answers
PDF
No ratings yet
C Lab Answers
24 pages
File Handling Final
PDF
No ratings yet
File Handling Final
11 pages