summaryrefslogtreecommitdiff
path: root/659/CH10
diff options
context:
space:
mode:
Diffstat (limited to '659/CH10')
-rwxr-xr-x659/CH10/EX1.cs/Casestudy.sci56
-rwxr-xr-x659/CH10/EX1.cs/Casestudy_output.PNGbin0 -> 41510 bytes
-rwxr-xr-x659/CH10/EX10.1/exm10_1.sce18
-rwxr-xr-x659/CH10/EX10.1/exm10_1_output.PNGbin0 -> 7462 bytes
-rwxr-xr-x659/CH10/EX10.2/exm10_2.sci18
-rwxr-xr-x659/CH10/EX10.2/exm10_2_output.PNGbin0 -> 5707 bytes
-rwxr-xr-x659/CH10/EX10.3/exm10_3.sce31
-rwxr-xr-x659/CH10/EX10.3/exm10_3_output.PNGbin0 -> 11514 bytes
-rwxr-xr-x659/CH10/EX10.4/exm10_4.sce33
-rwxr-xr-x659/CH10/EX10.4/exm10_4_output.PNGbin0 -> 11634 bytes
-rwxr-xr-x659/CH10/EX10.5/exm10_5.sce34
-rwxr-xr-x659/CH10/EX10.5/exm10_5_output.PNGbin0 -> 10444 bytes
12 files changed, 190 insertions, 0 deletions
diff --git a/659/CH10/EX1.cs/Casestudy.sci b/659/CH10/EX1.cs/Casestudy.sci
new file mode 100755
index 000000000..b7489ba23
--- /dev/null
+++ b/659/CH10/EX1.cs/Casestudy.sci
@@ -0,0 +1,56 @@
+// Case study: Chapter-10, Page No:341
+// Book Shop Inventory
+
+funcprot(0);
+//Defining functions
+function [string1]=get1()
+ string1=read(%io(1),1,1,'(a)');
+endfunction
+function [i] =look_up(table,s1,s2,m)
+ for i=1:m
+ x=strcmp(s1,table(i).title);
+ y=strcmp(s2,table(i).author);
+ if x==0 & y==0 then
+ return i; //Book found
+ end
+ end
+ i=-1; //Book not found
+endfunction
+
+//Creates array of structures
+book=[struct('author','Ritche','title','C Language','price',45.00,'month','May','year',1977,'publisher','PHI','quantity',10)
+ struct('author','Kochan','title','Programming in C','price',75.50,'month','July','year',1983,'publisher','Hayden','quantity',5)
+ struct('author','Balagurusamy','title','BASIC','price',30.00,'month','January','year',1984,'publisher','TMH','quantity',0)
+ struct('author','Balagurusamy','title','COBOL','price',60.00,'month','December','year',1988,'publisher','Macmillan','quantity',25)
+ ];
+n=size(book);
+no_of_records=n(1);
+response=' ', a=1;
+while ((response=='Y' | response=='y')|a==1)
+ //Read data
+ printf("Enter title and author name as per the list:\n");
+ printf("Title: \n");
+ title1=get1();
+ printf("Author:\n");
+ author1=get1();
+ //Calling index() function and
+ //Passing structure book to function look_up()
+ index=look_up(book,title1,author1,no_of_records);
+ //If book found then print the book detail otherwise not in list
+ if index~=-1 & index then //Book found
+ printf("% s %s",book(index).author, book(index).title);
+ printf("% .2f %s",book(index).price, book(index).month);
+ printf("% d %s\n",book(index).year, book(index).publisher);
+ quantity=input("Enter number of copies :");
+ if quantity<book(index).quantity then
+ printf("Cost of %d copies = %.2f\n",quantity,book(index).price*quantity);
+ else
+ printf("Required copies not in stock\n");
+ end
+ else
+ printf("Book not in list\n");
+ end
+ printf("\nDo you want any other book?(YES/NO):");
+ response=get1();a=2;
+end
+printf(" Thank you. Good Bye"); \ No newline at end of file
diff --git a/659/CH10/EX1.cs/Casestudy_output.PNG b/659/CH10/EX1.cs/Casestudy_output.PNG
new file mode 100755
index 000000000..631c32103
--- /dev/null
+++ b/659/CH10/EX1.cs/Casestudy_output.PNG
Binary files differ
diff --git a/659/CH10/EX10.1/exm10_1.sce b/659/CH10/EX10.1/exm10_1.sce
new file mode 100755
index 000000000..a95e1c22f
--- /dev/null
+++ b/659/CH10/EX10.1/exm10_1.sce
@@ -0,0 +1,18 @@
+// Example 10.1
+//Define a structure type,struct personal that would contain person name,-
+// date of joining and salary. Write a program to read this information from
+// keyboard and print same on the screen.
+
+funcprot(0);
+function [ ]=struc(n,d,m,y,s)
+ //Defining structure members
+ personal=struct('name',n,'day',d,'month',m,'year',y,'salary',s);
+ person=personal;
+ //Accessing structure members
+printf(" %s %d %s %d %.2f",person.name,person.day,person.month,person.year,person.salary);
+endfunction
+disp("Input values[Name day month year and salary]");
+//Reading data
+[name,day,month,year,salary]=scanf("%s %d %s %d %f");
+//Calling function struc()
+struc(name,day,month,year,salary); \ No newline at end of file
diff --git a/659/CH10/EX10.1/exm10_1_output.PNG b/659/CH10/EX10.1/exm10_1_output.PNG
new file mode 100755
index 000000000..5e60f8779
--- /dev/null
+++ b/659/CH10/EX10.1/exm10_1_output.PNG
Binary files differ
diff --git a/659/CH10/EX10.2/exm10_2.sci b/659/CH10/EX10.2/exm10_2.sci
new file mode 100755
index 000000000..8c1486842
--- /dev/null
+++ b/659/CH10/EX10.2/exm10_2.sci
@@ -0,0 +1,18 @@
+// Example 10.2
+// Write a program to illustrate the comparison of structure variables.
+
+function []=class()
+ //Defining structures
+ student1=struct('number',111,'name','Rao','marks',72.50);
+ student2=struct('number',222,'name','Raddy','marks',67.00);
+ student3=struct('number',[],'name',[],'marks',[]);
+ student3=student2;
+ if(student3==student2) , //Logical operation on structures
+ disp("Student2 and student 3 are same");
+ printf(" %d %s %f",student3.number,student3.name,student3.marks);
+ else
+ disp("Student2 and student 3 are not same");
+ end
+endfunction
+//calling function class
+class() \ No newline at end of file
diff --git a/659/CH10/EX10.2/exm10_2_output.PNG b/659/CH10/EX10.2/exm10_2_output.PNG
new file mode 100755
index 000000000..470ac181e
--- /dev/null
+++ b/659/CH10/EX10.2/exm10_2_output.PNG
Binary files differ
diff --git a/659/CH10/EX10.3/exm10_3.sce b/659/CH10/EX10.3/exm10_3.sce
new file mode 100755
index 000000000..b64b0a391
--- /dev/null
+++ b/659/CH10/EX10.3/exm10_3.sce
@@ -0,0 +1,31 @@
+// Example 10.3
+// Write a program to calculate the subject-wise and student-wise totals
+//and store them as a part of the structue.
+
+//Defining array of structures
+student=[struct('sub1',45,'sub2',67,'sub3',81,'total',0)
+ struct('sub1',75,'sub2',53,'sub3',69,'total',0)
+ struct('sub1',57,'sub2',36,'sub3',71,'total',0)
+ ];
+total=struct('sub1',0,'sub2',0,'sub3',0,'total',0);
+
+//Calculate the student-wise and subject-wise totals
+for i=1:3
+ student(i).total=student(i).sub1+student(i).sub2+student(i).sub3;
+ total.sub1=total.sub1+student(i).sub1;
+ total.sub2=total.sub2+student(i).sub2;
+ total.sub3=total.sub3+student(i).sub3;
+ total.total=total.total+student(i).total;
+end
+//Printing student-wise totals
+printf("STUDENT TOTAL\n");
+for i=1:3
+ printf("student(%d) %d\n",i,student(i).total);
+end
+//Printing subject-wise totals
+printf("SUBJECT TOTAL\n");
+printf(" %s %d\n","Subject 1",total.sub1);
+printf(" %s %d\n","Subject 2",total.sub2);
+printf(" %s %d\n","Subject 3",total.sub3);
+//Printing grand total
+printf("Grand Total = %d",total.total); \ No newline at end of file
diff --git a/659/CH10/EX10.3/exm10_3_output.PNG b/659/CH10/EX10.3/exm10_3_output.PNG
new file mode 100755
index 000000000..dbf221ed9
--- /dev/null
+++ b/659/CH10/EX10.3/exm10_3_output.PNG
Binary files differ
diff --git a/659/CH10/EX10.4/exm10_4.sce b/659/CH10/EX10.4/exm10_4.sce
new file mode 100755
index 000000000..6d857b7a0
--- /dev/null
+++ b/659/CH10/EX10.4/exm10_4.sce
@@ -0,0 +1,33 @@
+// Example 10.4
+//Rewrite the program of Example 10.3 to using an array member to represent
+//the three subjects.
+
+//Defining array of structures and array with in structure
+student(1)=[struct('sub',[45 67 81],'total',0)];
+student(2)=[struct('sub',[75 53 69],'total',0)];
+student(3)=[struct('sub',[57 36 71],'total',0)];
+total=student;
+for i=1:3
+ total.sub(i)=0;
+end
+total.total=0;
+//Calculate the student-wise and subject-wise totals
+for i=1:3
+ for j=1:3
+ student(i).total=student(i).total+student(i).sub(j);
+ total.sub(j)=total.sub(j)+student(i).sub(j);
+ end
+ total.total=total.total+student(i).total; //Grand total
+end
+//Printing student-wise totals
+printf("STUDENT TOTAL\n");
+for i=1:3
+ printf("student(%d) %d\n",i,student(i).total);
+end
+//Printing subject-wise totals
+printf("SUBJECT TOTAL\n");
+for j=1:3
+ printf("subject-(%d) %d\n",j,total.sub(j));
+end
+//Printing grand total
+printf("Grand Total = %d",total.total); \ No newline at end of file
diff --git a/659/CH10/EX10.4/exm10_4_output.PNG b/659/CH10/EX10.4/exm10_4_output.PNG
new file mode 100755
index 000000000..df2ae3906
--- /dev/null
+++ b/659/CH10/EX10.4/exm10_4_output.PNG
Binary files differ
diff --git a/659/CH10/EX10.5/exm10_5.sce b/659/CH10/EX10.5/exm10_5.sce
new file mode 100755
index 000000000..edbf68d86
--- /dev/null
+++ b/659/CH10/EX10.5/exm10_5.sce
@@ -0,0 +1,34 @@
+// Example 10.5
+//Write a simple program to illustrate the method of sending an entire
+//structure as a parameter to a function.
+
+funcprot(0);
+//Defining functions
+function [item]=update(product,p,q)
+ product.price=product.price+p;
+ product.quantity=product.quantity+q;
+ item=product;
+endfunction
+function [value] =mul(stock)
+ value=stock.price*stock.quantity;
+endfunction
+
+//Creates structure item
+item=struct('name','XYZ','price',25.75,'quantity',12);
+//Read data
+printf("Input increment values:");
+printf(" price increment and quantity increment\n");
+[p_increment,q_increment]=scanf("%f %d");
+
+//Calling update() and mul() functions
+//Passing structure item to functions update() and mul()
+//--------------------------------------------------
+item=update(item,p_increment,q_increment);
+value=mul(item);
+//--------------------------------------------------
+//Printing Results
+printf("Updated values of items\n");
+printf("Name :%s\n",item.name);
+printf("Price :%f\n",item.price);
+printf("Quantity :%d\n",item.quantity);
+printf("Value of item = %f\n",value); \ No newline at end of file
diff --git a/659/CH10/EX10.5/exm10_5_output.PNG b/659/CH10/EX10.5/exm10_5_output.PNG
new file mode 100755
index 000000000..073570229
--- /dev/null
+++ b/659/CH10/EX10.5/exm10_5_output.PNG
Binary files differ