diff options
Diffstat (limited to '659/CH8')
22 files changed, 262 insertions, 0 deletions
diff --git a/659/CH8/EX1.cs/Casestudy8_1.sce b/659/CH8/EX1.cs/Casestudy8_1.sce new file mode 100755 index 000000000..c9d6fa3de --- /dev/null +++ b/659/CH8/EX1.cs/Casestudy8_1.sce @@ -0,0 +1,31 @@ +// Csae study: Chapter-8, Page No:253
+// 1.Counting words in a text
+
+characters=0;words=0;lines1=0;
+printf(" KEY IN THE TEXT.\n");
+printf("GIVE ONE SPACE AFTER EACH WORD.\n");
+printf("WHEN COMPLETED,ENTER end\n");
+
+l=' ';
+while(l~='end')
+ l=read(%io(1),1,1,'(a)'); //Reading a line of text
+ if(l=='end') then
+ break;
+ end
+ line=[ascii(l)]; //Array of ascii values of line l
+ len=length(line); //compute length of line
+ for i=1:len
+ //ascii value of ' '(i.e.space) is 32
+ if(line(i)==32) then
+ words=words+1; //Count the number of words
+ end
+ end
+ lines1=lines1+1; //Count the number of lines
+ characters=characters+len; //Count the number of characters
+end
+//Printing results
+printf("Number of lines = %d\n",lines1);
+//Number of lines are added to words because last word of each line remains-
+//uncounted as words are incremented at the occurence of space.
+printf("Number of words = %d\n",words+lines1);
+printf("Number of characters = %d\n",characters);
\ No newline at end of file diff --git a/659/CH8/EX1.cs/Casestudy8_1_output.PNG b/659/CH8/EX1.cs/Casestudy8_1_output.PNG Binary files differnew file mode 100755 index 000000000..4b4bfead4 --- /dev/null +++ b/659/CH8/EX1.cs/Casestudy8_1_output.PNG diff --git a/659/CH8/EX2.cs/Casestudy8_2.sce b/659/CH8/EX2.cs/Casestudy8_2.sce new file mode 100755 index 000000000..5279f4453 --- /dev/null +++ b/659/CH8/EX2.cs/Casestudy8_2.sce @@ -0,0 +1,48 @@ +// Csae study: Chapter-8, Page No:253
+// 2.Processing of a customer list
+
+
+CUSTOMERS=10;
+printf(" Input names and telephone numbers\n");
+printf(" [Names must have First,Second and Last_name]\n");
+for i=1:CUSTOMERS
+ //Read data
+ [first_name(i),second_name(i),surname(i),telephone(i)]=scanf("%s %s %s %s");
+ //Converting full name to surname with initials
+ l1=length(surname(i)); //Compute length of surname at i
+ name(i)=strncpy(surname(i),l1) ;
+ name(i)=strcat([name(i),',']);
+ dummy(1)=part(first_name(i,1),1);
+ name(i)=strcat([name(i),dummy]);
+ name(i)=strcat([name(i),'.']);
+ dummy(1)=part(second_name(i,1),1);
+ name(i)=strcat([name(i),dummy]);
+end
+//Alphabetical odering of surnames
+for i=1:CUSTOMERS //Outer loop begins
+ for j=2:CUSTOMERS-i+1 //Inner loop begins
+ k=strcmp(name(j-1),name(j));
+ if(k>0) then
+
+ //Swaping names
+ l1=length(name(j-1));
+ l2=length(name(j));
+ dummy=strncpy(name(j-1),l1);
+ name(j-1)=strncpy(name(j),l2);
+ l3=length(dummy);
+ name(j)=strncpy(dummy,l3);
+
+ //Swapping telephone numbers
+ l3=length(telephone(j-1));
+ l4=length(telephone(j));
+ dummy=strncpy(telephone(j-1),l3);
+ telephone(j-1)=strncpy(telephone(j),l4);
+ telephone(j)=strncpy(dummy,l3);
+ end
+ end //Inner loop ends
+end //Outer loop ends
+//Printing alphabetical list
+disp("CUSTOMER LIST IN ALPHABETICAL ORDER");
+for i=1:CUSTOMERS
+ printf("%-20s\t %-10s\n",name(i),telephone(i));
+end
\ No newline at end of file diff --git a/659/CH8/EX2.cs/Casestudy8_2_output.PNG b/659/CH8/EX2.cs/Casestudy8_2_output.PNG Binary files differnew file mode 100755 index 000000000..e11091a4b --- /dev/null +++ b/659/CH8/EX2.cs/Casestudy8_2_output.PNG diff --git a/659/CH8/EX8.1/exm8_1.sce b/659/CH8/EX8.1/exm8_1.sce new file mode 100755 index 000000000..bd31fe0ed --- /dev/null +++ b/659/CH8/EX8.1/exm8_1.sce @@ -0,0 +1,9 @@ +// Exampple 8.1
+//Write a program to read a series of words from terminal using scanf function.
+
+//Read data using scanf function
+disp("Enter text:")
+[word1,word2,word3,word4]=scanf("%s %s %s %s");
+//Printing the results
+printf("word1 = %s\nword2 = %s\n",word1,word2);
+printf("word3 = %s\nword4 = %s\n",word3,word4);
\ No newline at end of file diff --git a/659/CH8/EX8.1/exm8_1_output.PNG b/659/CH8/EX8.1/exm8_1_output.PNG Binary files differnew file mode 100755 index 000000000..f492a0214 --- /dev/null +++ b/659/CH8/EX8.1/exm8_1_output.PNG diff --git a/659/CH8/EX8.2/exm8_2.sce b/659/CH8/EX8.2/exm8_2.sce new file mode 100755 index 000000000..2f824cc6d --- /dev/null +++ b/659/CH8/EX8.2/exm8_2.sce @@ -0,0 +1,7 @@ +// Example 8.2
+//Write a program to read a line of text containing a series of-
+//words from the terminal.
+
+disp("Enter text. Press <Return> at end");
+line=read(%io(1),1,1,'(a)'); //Read a line
+disp(line); //Display line
diff --git a/659/CH8/EX8.2/exm8_2_output.PNG b/659/CH8/EX8.2/exm8_2_output.PNG Binary files differnew file mode 100755 index 000000000..6b0a6dacf --- /dev/null +++ b/659/CH8/EX8.2/exm8_2_output.PNG diff --git a/659/CH8/EX8.3/exm8_3.sce b/659/CH8/EX8.3/exm8_3.sce new file mode 100755 index 000000000..4033a4fdb --- /dev/null +++ b/659/CH8/EX8.3/exm8_3.sce @@ -0,0 +1,16 @@ +// Example 8.3
+//Write a program to copy one string into another and count the number
+//of characters copied.
+
+//Read data using scanf function
+disp("Enter a string:")
+[string2]=scanf("%s"); //Read string
+l=length(string2); //Compute the length
+string1=' '; //string1 is empty
+for i=1:l
+ string1=string1+ part(string2,i);
+end
+//Printing the results
+printf(" %s\n",string1);
+printf(" Number of characters = %d\n",l);
+
diff --git a/659/CH8/EX8.3/exm8_3_output.PNG b/659/CH8/EX8.3/exm8_3_output.PNG Binary files differnew file mode 100755 index 000000000..78dc09556 --- /dev/null +++ b/659/CH8/EX8.3/exm8_3_output.PNG diff --git a/659/CH8/EX8.4/exm8_4.sce b/659/CH8/EX8.4/exm8_4.sce new file mode 100755 index 000000000..d9b2e9f72 --- /dev/null +++ b/659/CH8/EX8.4/exm8_4.sce @@ -0,0 +1,17 @@ +// Exampple 8.4
+//Write a program to store the string "United Kingdom" in the array country-
+//and display the string under various format specifications.
+
+
+country='United Kingdom';
+printf("\n");
+printf("*123456789012345*\n");
+printf("--------\n");
+printf("%15s\n",country);
+printf("%5s\n",country);
+printf("%15.6s\n",country);
+printf("%-15.6s\n",country);
+printf("%15.0s\n",country);
+printf("%.3s\n",country);
+printf("%s\n",country);
+printf("--------\n");
diff --git a/659/CH8/EX8.4/exm8_4_output.PNG b/659/CH8/EX8.4/exm8_4_output.PNG Binary files differnew file mode 100755 index 000000000..e2d7718e7 --- /dev/null +++ b/659/CH8/EX8.4/exm8_4_output.PNG diff --git a/659/CH8/EX8.5/exm8_5.sce b/659/CH8/EX8.5/exm8_5.sce new file mode 100755 index 000000000..da0af3366 --- /dev/null +++ b/659/CH8/EX8.5/exm8_5.sce @@ -0,0 +1,40 @@ +// Example 8.5
+//Write a program using for loop to print the following output:
+// C
+// CP
+// ....
+// ....
+// CProgrammimg
+// CProgrammimg
+// ....
+// ....
+// CPr
+// CP
+// C
+string1='CProgramming';
+printf(" -------------\n");
+f=' ';
+for i=1:12
+ f=f+part(string1,i);
+
+ printf("|%-13s|\n",f);
+end
+printf("|-------------|\n");
+for j=0:11
+ s=' ';
+ for i=1:12-j
+ s=s+part(string1,i);
+ end
+ printf("|%-13s|\n",s);
+end
+printf(" -------------");
+//for c=0:11
+// d=c+1;
+// mprintf("|%-12.*s|\n",d,string1);
+//end
+//disp("---------------------");
+//for c=11:c-1:0
+// d=c+1;
+// printf("|%-12.*s|\n",d,string1);
+//end
+//disp("----------------------");
\ No newline at end of file diff --git a/659/CH8/EX8.5/exm8_5_output.PNG b/659/CH8/EX8.5/exm8_5_output.PNG Binary files differnew file mode 100755 index 000000000..c35461ad4 --- /dev/null +++ b/659/CH8/EX8.5/exm8_5_output.PNG diff --git a/659/CH8/EX8.6/exm8_6.sce b/659/CH8/EX8.6/exm8_6.sce new file mode 100755 index 000000000..11c0e0a72 --- /dev/null +++ b/659/CH8/EX8.6/exm8_6.sce @@ -0,0 +1,12 @@ +// Example 8.6
+//Write a program which would print the alphabet set a to z A to Z in decimal-
+//character form.
+
+for c=65:122
+ if(c>90&c<97) then
+ continue; //Terminate current iteration
+ end
+ c1=ascii(c); //Convert ascii value to character
+ printf("|%4d - %c\",c,c1);
+end
+printf("|\n")
\ No newline at end of file diff --git a/659/CH8/EX8.6/exm8_6_output.PNG b/659/CH8/EX8.6/exm8_6_output.PNG Binary files differnew file mode 100755 index 000000000..10591fa9c --- /dev/null +++ b/659/CH8/EX8.6/exm8_6_output.PNG diff --git a/659/CH8/EX8.7/exm8_7.sce b/659/CH8/EX8.7/exm8_7.sce new file mode 100755 index 000000000..68bb6f90f --- /dev/null +++ b/659/CH8/EX8.7/exm8_7.sce @@ -0,0 +1,19 @@ +// Example 8.7
+//The name of employees of an organization are stored in three arrays namely-
+//first_name,second_name and last_name.
+//Write a program to concatinate the three parts into one string called name.
+
+
+//Store the name in the three arrays
+first_name=['VISWANATH'];
+second_name=['PRATAP'];
+last_name=['SINGH'];
+
+//Concatinate three parts into one
+name=[first_name second_name last_name];
+// Print the result
+for i=1:3
+ printf("%s ",name(i));
+end
+//Statement below can also be used to print the result
+//disp(name);
diff --git a/659/CH8/EX8.7/exm8_7_output.PNG b/659/CH8/EX8.7/exm8_7_output.PNG Binary files differnew file mode 100755 index 000000000..c82b40faa --- /dev/null +++ b/659/CH8/EX8.7/exm8_7_output.PNG diff --git a/659/CH8/EX8.8/exm8_8.sce b/659/CH8/EX8.8/exm8_8.sce new file mode 100755 index 000000000..41a558522 --- /dev/null +++ b/659/CH8/EX8.8/exm8_8.sce @@ -0,0 +1,32 @@ +// Example 8.8
+//s1,s2 and s3 are three string variables. Write a program to read two string-
+//constants in to s1 and s2 and compare whether they are equal or not,join-
+//them together. Then copy contents of s1 to variable s3. At the end program-
+// should print all three variables and their lengths
+
+
+//Read data
+printf("Enter two string constants\n");
+[s1 s2]=scanf("%s %s");
+
+//Comparing two strings
+x=strcmp(s1,s2);
+if x~=0 then
+ printf("String are not equal\n");
+ //Concatinate two strings s1 and s2
+ s1=strcat([s1,s2]);
+else
+ printf("String are equal\n");
+end
+
+l1=length(s1);
+//Coping s1 to s3
+s3=strncpy(s1,l1);
+//finding length of strings
+l2=length(s2);
+l3=length(s3);
+//Output
+printf("s1 = %s\t length = %d characters\n",s1,l1);
+printf("s2= %s\t length = %d characters\n",s2,l2);
+printf("s3= %s\t length = %d characters\n",s3,l3);
+
diff --git a/659/CH8/EX8.8/exm8_8_output.PNG b/659/CH8/EX8.8/exm8_8_output.PNG Binary files differnew file mode 100755 index 000000000..d86ff3867 --- /dev/null +++ b/659/CH8/EX8.8/exm8_8_output.PNG diff --git a/659/CH8/EX8.9/exm8_9.sce b/659/CH8/EX8.9/exm8_9.sce new file mode 100755 index 000000000..d65e65504 --- /dev/null +++ b/659/CH8/EX8.9/exm8_9.sce @@ -0,0 +1,31 @@ +// Example 8.9
+//Write a program that would sort a list of names in alphabetical order.
+
+ITEMS=5;
+//Reading the list
+printf("Enter names of %d items\n",ITEMS);
+i=1;
+while(i<=ITEMS)
+ string1(i)=scanf("%s");
+ i=i+1;
+end
+//Sorting begins
+for i=1:ITEMS //Outer loop begins
+ for j=2:ITEMS-i+1 //Inner loop begins
+ k=strcmp(string1(j-1),string1(j))
+ if(k>0) then
+ //Compute length and Exchange of contents
+ l1=length(string1(j-1));
+ l2=length(string1(j));
+ dummy=strncpy(string1(j-1),l1);
+ string1(j-1)=strncpy(string1(j),l2);
+ l3=length(dummy);
+ string1(j)=strncpy(dummy,l3);
+ end
+ end //Inner loop ends
+end //Outer loop ends
+//Sorting completed
+disp("Alphabetical list");
+for i=1:ITEMS
+ printf("%s\n",string1(i));
+end
diff --git a/659/CH8/EX8.9/exm8_9_outout.PNG b/659/CH8/EX8.9/exm8_9_outout.PNG Binary files differnew file mode 100755 index 000000000..f1d63a4ad --- /dev/null +++ b/659/CH8/EX8.9/exm8_9_outout.PNG |