Welcome





Monday, January 31, 2011

List of Teams

Team 1 : 26,27,35,36,43,64,66.
Team 2 : 71,49,31,30,29,23,876.
Team 3 : 46,56,5,48,12,70,60.
Team 4 : 25,47,51,54,44,9,32,58.
Team 5 : 7,13,45,14,40,62,63.
Team 6 : 4,6,8,18,21,39,57,24.
Team 7 : 33,34,38,55,59,61,821,28.
Team 8 : 50,52,3,17,65,22,53,20.
Team 9 : 2,73,41,1,42,10,15,19.

ASSIGNMENTS

1.  Creation of Static Libraries in C/C++.
2.  Printing of labels/Addresses in Telugu/Hindi.
3.  Invoke C/C++ functions from Java.
4.  Implementation of Garbage Collector.
5.  Secure Coding in C.
6.  Solitaire Game.
7.  Spreadsheet in Linux.
8.  Dividend Warrant (With Rupees Symbol  `).
9.  Virtual table - Implementation.
10. Personal Calendar / Event Organizer.



Select your assignment by commenting on this post. 


Monday, January 17, 2011

Language Reference Manuals

Coming towards the end of the semester, I just googled a few manuals. Not sure if they are authentic or official or anything. Hopefully they might be useful:

C


C++

Java

Class Test 1 - 2010

The question paper can be found here or on the Programming Languages page

Please post answers to the questions as comments. This post will later be updated with the answers.

Part A:
1.
a) False
b) True
c) False
d) False because 099L refers to octal long numbers which are not posible

2.

3. Order of evaluation in java is not specified.

4.

5.

6.

Part B:

1.

2.
on SOUCE.
3.

Tutorial # 2

13. How much total space is required for the following C++ code fragment?
{
int a,b,c;
{
int d,e;
{
int f;
}
}
int g,h,i;
}
Assume each integer occupies 4 bytes.

When we exit the inner scopes, the variable memory is deallocated and hence, only outer variables have memory. Thus, the above code fragment requires at most 24 bytes of memory as at any given time, not more than 6 integer values are alive.


14. State whether the following statements are True or False:
(i) C++ programs use dynamic scoping when accessing a macro
[True] This is because macros are expanded textually.
(ii) In C++ expressions, operands in binary evaluation are evaluated in a left-to right order.
[False] This statement is false because the evaluation order isn't specified in C++ unlike Java, which is from left-right.


15. Why do Java compilers generate byte code instead of machine code?

Java compilers generate byte code instead of machine code to impart portability to the code.


16. What does the following C code do?
int i=2, j=4;
int list[]={6,7,18,-8,22,104};
list[++i,j]=77;

The above C code modifies the above values as:
i=3
j=4
list[]={6,7,18,-8,77,104}


17. What is the output of the following Java program?
System.out.println(1.0 + 1.0 + 1.0e17 - 1.0e17);
System.out.println(1.0e17 - 1.0e17 + 1.0 +1.0);

The o/p for the first statement is justified because of the Left-right execution in expression evaluation in Java. Here, boundary limits are crossed and hence 0.
In the second statement, answer is 2 because of the 1+1 evaluation.


18. What is type completeness principle?

The type completeness principle states that no operations should be arbitrarily restricted in the types of values involved.


19. What are the differences between Java and C++ arrays?

There are main 3 differences between C++ Arrays and Java Arrays:
(i) C++ arrays are static type(i.e., user needs to provide size at compile time itself), while Java arrays are of flexible type(because of obj.type declaration)
(ii) One can determine the length of arrays in Java easily through the syntax: arrayname.length; while this is not possible in C++.
(iii) C++ Arrays are either stored in the Stack/Heap/Static area, while Java arrays are stored only in the Heap area.

20. Explain the difference between type declaration and type definition in C++ with an example.

(i) A declaration introduces names into a translation unit or redeclares names introduced by previous declarations. A declaration specifies the interpretation and attributes of these names.
(ii) A declaration is a definition unless it declares a function without specifying the function's body, it contains the extern specifier or a linkage-specification and neither an initializer nor a function-body, it declares a static data member in a class declaration , it is a class name declaration, or it is a typedef declaration, a using-declaration, or a using-directive.


21. What does the following Java statement do? (where marks is of type int)
boolean is A = (90<=marks<=100); This code produces a syntax error as logical comparisons in Java produce Boolean values, and Boolean values can't be compared with integer types. For correct of code, we can write: boolean is A: ((90 <= marks) && (marks <= 100))



22. What is the output of the following Java program? 
 double x = double (3/5); 
 System.out.println(x); 

 The output is 0


23. What happens when you evaluate the following expressions in Java? 17/0
17%0 
17.0/0.0 
17.0%0.0 

All the 4 statements produce errors.
The 1st and 2nd expressions produce exceptions.
While, the 3rd gives Infinite number. 
Lastly, 4th expression gives Not a number. 





Please post answers to these questions as comments for this post. They will be later integrated in it.

Tutorial # 1

1. What are scripting languages? Give examples.

Scripting languages are used to glue together subsystems written in other languages. They are interpreted at run-time. This means that every time you want to run the program, a separate program needs to read the code, interpret it, and then follow the instructions in the code. Hence these programs run slower.
Some examples are: AppleScript, JavaScript, Perl, Python, PHP, Smalltalk etc



2. What are copy and reference semantics? How are they available in C++ and Java?

In copy semantics, all components of the composite data type are copied when an object is assigned.
In reference semantics,only the starting address of the object is copied when an object is assigned.
Generally c++ follows copy semantics.Reference semantics can be implemented using pointers.For example,the copy semantics in c++ can be shown as:
struct emp
{
double empno;
float salary;
};
emp e1={01254,20000};
emp e2;
e2=e1; //copy semantics
Likewise reference semantics can be implemented as:
emp* pe1=new emp;
emp* pe2=new emp;
*pe1=e1;
pe2=pe1;
Generally, java follows reference semantics for objects and copy semantics for primitive values.
class emp
{
double empno;
double sal;
}
emp e1=new emp(01245,20000);
emp e2;
e2=e1; //reference semantics
However, copy semantics can also be implemented using clone() method.
emp e1=new emp(01245,20000);
emp e2;
e2=e1.clone();//copy semantics


3. What are storable values? List some storable values in Java.

The values which can be stored in single storage cell are called storable values. In general, all languages regard particular data types to be storable values by default.

In java, primitive values and pointers to objects are considered as storable values.
Objects themselves are not storable. But implicitly they are accessed by pointers.
Examples: int,byte,double etc


4. What are expression-oriented languages?

5. Why is a language that supports only static storage allocation limited?

6. What are the features of ALGOL family of languages?

7. Why does a C/C++ programmer enclose a union inside another structure?

In an ordinary union, only one data member can be referenced at a time. In order to make it a discriminated union, we need to provide tags..

enum btreePageTypeTag { NEXT, BTREE };// tags

struct btreePageType {
btreePageTypeTag tag; //tag used to check
union {
long next;
diskNodeType btree;
} u;
};


8. Why are recursive types not available in most languages? What concepts are used to define recursive types?

9. In many programming languages, strings are defined as arrays of characters. Compare the consequences when the array is static, dynamic and flexible. (Assignment, Comparison, Concatenation)

10. What are visibility and lifetime? What is the purpose of local, global and static variables? What are initialized values in C/C++ and Java?

11. Write the corresponding if else statements:
int a, b,c, d, e;
a?b:c;
a?b:c?d:e;
a?b?c:d:e;
a?b:c?d:e?;

Please post answers to these questions as comments for this post. They will be later integrated in it.

Friday, January 7, 2011

Address of Senior's Blog

If you have any doubts regarding this blog you may visit the seniors blog (http://www.programmingou.blogspot.com) Now they are using it for DBMS, you can view the home and starting pages of the blog to have the content related to programming languages subject.


Click here to go to senior's blog.

Monday, January 3, 2011

Welcome

This blog is meant for II Year CSE Students of the University College of Engineering (Autonomous), Osmania University, 2009-2013 batch, pursuing the course CS 253 UE: Programming Languages.