tailieunhanh - Lecture Introduction to Computer Programming - Lecture 25

This chapter focuses on logic pro-gramming with Prolog, studying its applications in natural language processing and , problem solving. The main contents of this chapter include all of the following: Logic and horn clauses, logic programming in prolog, prolog program elements. | CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 25 Thanks for Lecture Slides: Dr. Sadaf Tanveer, Assistant Professor, CIIT 1 Structures: Introduction Real world data doesn’t usually deal with information like int, float etc. we have entities that are collections of items, having its own attributes. Example: a ‘book’ is a collection attributes such as title, author, call number, publisher, number of pages, date of publication, etc. All data items are not similar for example author is a string, whereas number of pages is an integer. For dealing with such collections, C provides a data type called ‘structure’. A structure combines different data types that constitutes an entity. CSC 141 Introduction to Computer Programming 2 Introduction: Why Use Structures If data about say 3 such books is to be stored, then we can follow two approaches: Construct individual arrays, one for storing names, another for storing prices and still another for storing number of pages. Use a structure variable. For the sake of convenience assume that the names of books would be single character long. Let us begin with a program that uses arrays. CSC 141 Introduction to Computer Programming 3 void main( ) { char name[3] ; float price[3] ; int pages[3], i ; printf ( "\nEnter names, prices and no. of pages of 3 books\n" ) ; for ( i = 0 ; i <= 2 ; i++ ) scanf ( “\t %c %f %d", &name[i], &price[i], &pages[i] ); printf ( "\n Your entered information \n" ) ; for ( i = 0 ; i <= 2 ; i++ ) printf ( “\t %c \n %f \n %d\n", name[i], price[i], pages[i] ); } Introduction: Old Approach CSC 141 Introduction to Computer Programming 4 Introduction: Output of program Enter names, prices and no. of pages of 3 books A 354 C 682 F 512 Your entered information A 354 C 682 F 512 CSC 141 Introduction to Computer Programming 5 This approach allows you to . | CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 25 Thanks for Lecture Slides: Dr. Sadaf Tanveer, Assistant Professor, CIIT 1 Structures: Introduction Real world data doesn’t usually deal with information like int, float etc. we have entities that are collections of items, having its own attributes. Example: a ‘book’ is a collection attributes such as title, author, call number, publisher, number of pages, date of publication, etc. All data items are not similar for example author is a string, whereas number of pages is an integer. For dealing with such collections, C provides a data type called ‘structure’. A structure combines different data types that constitutes an entity. CSC 141 Introduction to Computer Programming 2 Introduction: Why Use Structures If data about say 3 such books is to be stored, then we can follow two approaches: Construct individual arrays, one for .

TỪ KHÓA LIÊN QUAN