Friday 3 December 2010

Refer to the information provided in Figure 7.2 below to answer the following questions

3. Refer to Figure 7.2. This corn producer produces 100 bushels of corn and sells each bushel at $5. The cost of producing each unit bushel is $2. This corn producer's total revenue is


A) $20. 
B) $200. 
C) $300. 
D) $500

If economic profit is zero, a firm

A) earns a negative rate of return
B) will leave the industry 
C) earns a positive but below normal rate of return 
D) earns exactly a normal rate of return

Total revenue minus total cost is equal to

A) the rate of return 
B) marginal revenue
C) profit  
D) net cost 

Thursday 2 December 2010

Fill in the Comparison Table with appropriate answers expressing 5 key differences of :- •Super computer, •Main Frame, • Personal Computers , •PDA’s .

Solution:-



Cost
Performance
Reliability
Size
Installed in numbers
Super computer
Very high
Highest
Most reliable
Very huge in Size
Less
Main Frame
High, less costly than super computers
High, not better than super computers
Reliable, not reliable than super computers
Smaller than Super computers
More than super computers
Personal computers
Average
Good, not better than main frame
Reliable but not more than Main frames and super computers
Very Small as compared to main Frames and super computers
Largest in number
PDA’s
Less
Not better than personal computers
Not reliable as compared to above mentioned
Smallest in size
Less than personal computers

Suppose the market demand and market supply for coffee is given by the Qd = 850 – 15P Qs = 400 + 30P

A. Find quantity demanded and quantity supplied when the price of
coffee is Rs. 8. Is there a surplus or shortage in the production of
coffee? What should happen to the price of coffee?
B. Find the equilibrium price for  coffee by using given demand and
supply equations.
C. Prove that the price found in part (B) is an equilibrium price.
D. Show the equilibrium condition in coffee market graphically.



Solution Part A: Quantity demanded is found by letting P equal to Rs. 8 in the demand equation.
Thus, 
                                                     Qd = 850 – 15P
                                                           = 850 – 15(8)
                                                           = 850 – 120
                                                           = 730
Similarly,
                                                     Qs = 400 + 30P
                                                          = 400 + 30(8)
                                                          = 400 + 240
                                                          = 640


There is a shortage of production since 730 units are demanded and 640 units
are supplied when the price per unit is Rs. 8. There is therefore  upward
pressure on the Rs. 8 price for coffee.

Solution Part B: The equilibrium price for coffee is found by equating Qd and Qs.
Qd = Qs
850 – 15P = 400+30P
30P + 15P = 850 – 400
45P = 450
P = 10

Solution Part C: At equilibrium, the quantity demanded must equal the quantity supplied.
Substituting the Rs.10 equilibrium price into the market demand and market
supply equations:


Qs = 400 +30P                                                   Qd = 850 – 15P
      = 400 + 30(10)                                                   = 850 – 15 (10)
      = 400 + 300                                                        = 850 - 150
      = 700                                                                  = 700
                                                                      
We find that quantity demanded and quantity supplied each equals 700 units.
Solution Part D:

Problem Statement: Comparing two arrays for equality or matching indexes You are required to write a program which will take input from user in two integer arrays. The program should compare both arrays for checking if both arrays are totally identical (Exactly same). If not, then program should determine the matching indexes of both arrays. Matching indexes means that first element of array1 should be equal to first element of array2 and so on.

Example of two identical (Exactly same) arrays:

Array1        Array2
1             1
2             2
3             3
5             5
7             7
9             9
11            11
13            13
15            15
17            17


Example of two arrays with some matching elements:

Array1        Array2
1             7
2             9
3             3
5             4
7             6
9             8
11            11
13            15
8             8
17            17

Here elements on index 3, 7, 9, and 10 of both arrays are same.



Detailed Description:

 The program should take 10 integer inputs from user in arrray1 and array2.
  • After taking inputs in both arrays, you should pass both arrays to a function named match.
  • If both arrays are exactly same, the program should display a message “Both arrays are identical”.
  • If both arrays are not exactly same, then program should match the indexes which have same elements in both arrays and display the matching indexes.
  • If there is no element matching in both arrays, the program should display a message
  “There is no matching element in both arrays”.
  • Implementation regarding comparison of arrays and displaying message should be inside the function match.

Sample Output for two exactly same arrays

Please enter 10 integers for array1:
Enter element 1 : 1
Enter element 2 : 3
Enter element 3 : 5
Enter element 4 : 7
Enter element 5 : 9
Enter element 6 : 11
Enter element 7 : 13
Enter element 8 : 15
Enter element 9 : 17
Enter element 10 : 19

Please enter 10 integers for array2:
Enter element 1 : 1
Enter element 2 : 3
Enter element 3 : 5
Enter element 4 : 7
Enter element 5 : 9
Enter element 6 : 11
Enter element 7 : 13
Enter element 8 : 15
Enter element 9 : 17
Enter element 10 : 19

Both arrays are identical


Sample Output for arrays with some matching indexes

Please enter 10 integers for array1:
Enter element 1 : 1
Enter element 2 : 3
Enter element 3 : 5
Enter element 4 : 7
Enter element 5 : 9
Enter element 6 : 11
Enter element 7 : 13
Enter element 8 : 15
Enter element 9 : 17
Enter element 10 : 19

Please enter 10 integers for array2:
Enter element 1 : 2
Enter element 2 : 4
Enter element 3 : 5
Enter element 4 : 6
Enter element 5 : 9
Enter element 6 : 12
Enter element 7 : 14
Enter element 8 : 16
Enter element 9 : 17
Enter element 10 : 20


Both arrays have same elements on
Index 3
Index 5
Index 9

/********************* ASSIGNMENT NO. 2  SOLUTION ****************/

#include <iostream.h>
#include <conio.h>

void match(int[], int[]);  // Declaration of match function for matching 2 arrays

main()
{
    int array1[10], array2[10];

// Taking 10 integer inputs from user in array 1
  cout << "Please enter 10 integers for array1:" << endl;
  for(int i=0; i<10; i++)
   {
       cout << "Enter element " << i+1 <<" : ";
       cin >> array1[i];
   }
  
// Taking 10 integer inputs from user in array 2          
  cout << endl<<"Please enter 10 integers for array2:" << endl;
  for(int i=0; i<10; i++)
   {
       cout << "Enter element " << i+1 <<" : ";
       cin >> array2[i];
   }

//Passing both arrays to function match
match(array1, array2);

getch();
} //End of main() function

//Definition of function match taking two arrays as arguments
void match(int Array1[], int Array2[])
 {

int check = 0;  //This variable will be used to checked whether arrays are identical, with some same elements or have no same element
 
/* In the following loop, we are comparing elements at same indexes of both arrays. If each
element of both arrays is same, then variable "check" will be incremented 10 times.*/
  for(int i=0; i<10; i++)
       {
         if(Array1[i] == Array2[i])
          {
            check++;
          }
       }
      
   
/* If variable check is incremented 10 times then it means that both arrays are exactly same*/
  if(check == 10)
     {
       cout << endl << "Both arrays are identical";
     }   
   

/* If variable check is less than 10 and more than 0, it means that there are some elements which
are same in both arrays at same indexes. So, here we will display matching indexes in both arrays*/    
  else if (check <10 && check > 0)
     {
       cout << endl<<"Both arrays have same elements on "<<endl;
           for(int j=0; j<10; j++)
             {
               if(Array1[j] == Array2[j])
                   {
                     cout << "index " << j+1 << endl; 
                   }
              }
        }
   
   
/* If variable check=0, it means that there is no matching element in the both arrays*/
  else if(check == 0)
     {
       cout << endl << "There is no matching element in both arrays";
     }   

}  

Problem Statement: Calculating No. of A Grades in Class You are required to write a program which should take input from user in the form of characters A or B. Based upon user’s input you should calculate no. of A grades. You should use while loop or do/while loop for taking input and if / else condition for making decisions.

Detailed Description:

The program should display like;

Please Enter Grade (‘A’ OR ‘B’ )

Then the program should take 10 inputs one by one,

  • After taking 10 inputs, you should display no. of A grades.
  • If A grades are less than or equal to 2, you should display a message “Your class is Poor!”.
  • If A grades are less than or equal to 7, you should display a message “Your class is Good!”.
  • If A grades are greater than or equal to 8, you should display a message “Your class is Brilliant!”.
  • The user should enter either A or B. If user has entered other than A or B, e.g. C,D,E etc. Your program should display a message like; 
     "Please Enter 'A' or 'B' grade only!"

Sample Input and Output

Please Enter Grade of student 1 :
A
Please Enter Grade of student 2 :
A
Please Enter Grade of student 3 :
B
Please Enter Grade of student 4 :
A
Please Enter Grade of student 5 :
B
Please Enter Grade of student 6 :
B
Please Enter Grade of student 7 :
A
Please Enter Grade of student 8 :
B
Please Enter Grade of student 9 :
C

Please Enter ‘A’ or ‘B’ grade only!
Please Enter Grade of student 9 :
A

Please Enter Grade of student 10 :
A


   
Total No. of A Grades = 6

Your Class is Good!



//this programme takes the grades A and B//
using namespace std;
#include <iostream>
#include <conio.h>


main()
{
 int totalstudent=1;
 int a =0,b=0;

 char grade(1);

 while (totalstudent <= 10)
     {
           cout<<"Please Enter The Grade of students "<<totalstudent<<" :\n";
           cin>>grade;
           if (grade=='a' or grade =='A')
           {
              a++;
              totalstudent++;
           }
           else if (grade=='b' or grade =='B')
           {
              b++;
              totalstudent++;
           }
           else
           {
           cout<<"\nPlease Enter 'A' or 'B' grade only! \n";  
          
           }
     }
      
       cout<<"Total No. of A Grades "<<a<<" :\n";
 
      
       if (a <=2)
       {
          cout<<"\nYour class is Poor!\n";
       }else if (a <=7)
          cout<<"\nYour class is Good!\n";
       else
       {
          cout<<"\nYour class is Brilliant!\n";
       }
getche();

}

Your Company wants to serve as trustee for the project of Social welfare Foundation, which is working for poor and destitute. Write a letter of inquiry to the head of the foundation and ask about funding, benefits, desired results and facilities being offered to the people.

Key:


LETTER
Following is the recommended format for any type of business letter:

November 21, 2010
Sender's address
742 Green Town
City12345 (e.g. Lahore)

Recipient's name and address
Project Manager
XYZ Housing Society
City ABC

Salutation
Dear Sir or on the situation

Body of the Letter
(Content)

Closing
Yours truly / sincerely
Signature
Type full name and signature above

Correct organization of a business message is important for both the audience and the communicator? Explain

Key:
A good organization of a message will:
1. Improve productivity. ( See the next page)
By arranging the ideas in a logical and diplomatic way, you will increase the chances of satisfying the audience’s needs.
2. Boost understanding.
Audience will understand exactly what you mean
3. Increase acceptance.
Audience will comparatively believe the information/message conveyed.
4. Save audience’ time.
Well organized messages contain relevant information, so the audience does not waste time with superfluous information.

Make the following statements considerate:

1.      We are delighted to announce that we are opening a new store in Karachi.
2.      We don’t accept your claim of purchased goods but we have replacement for other goods.
3.      As our meeting venue is not finalized, we can call you at any other place.
4.      Our manager will be busy in the meeting on Monday, so he cannot meet you this time.
5.      The flights are cancelled, we are sorry that we will not be able to entertain you due to air smoke in Europe.
Answers:

  1. It will be happy news for you that you will find our new store in Karachi.

  1. Your claim for purchased goods is accepted with replacement for other goods.


  1. You will be informed about the meeting place later.

  1. Your appointment with the manager is scheduled on Tuesday due to an important meeting on Monday

  1. As soon as the air space is clear in Europe, the new schedule of flights will be announced.

Write a recursive function that takes three arguments (an integer array, starting subscript ‘s’ and ending subscript ‘e’ )

In first recursive call, the function should display the array from subscript ‘s’ (s = 0)
to ‘e’ (e =
size of array). In each successive call, the function should print the array from index
s+1 to e. T
function should stop processing and return when starting subscript becomes equal to
ending
subscript.
For example, if user enters values for array 2, 3, 4, 5, 6 then the recursive function
must display the following output.
2 3 4 5 6
3 4 5 6
4 5 6
5 6
6
answer
#include <iostream.h>;
void PrintArray(int arrayInput[], int &s, int &e);
main ( ) 
{
int pause;
int TestArray [6] = {1,2,3,4,5,6};
int StartPoint = 0;
int EndPoint = 5;
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cin >> pause;
}
void PrintArray(int arrayInput[], int& s, int& e)

{
for (int i = s; i<= e; i++)
{
cout<<  arrayInput[i];

s=s+1;

}

Write the procedure of data insertion in middle of the files by Merge Method practiced in older systems?

· Opened the data file and a new empty file. 
· Started reading the data file from beginning of it.
· Kept on copying the read data into the new file until the location we want to
insert data into is reached. 
· Inserted (appended) new data in the new file.
· Skipped or jumped the data in the data file that is to be overwritten or
replaced. 
· Copied (appended) the remaining part of the file at the end of the new file

Find out error in the code given below:

if ( num % 2 = 0 )
cout << "The number is even" << endl;
if ( num % 2 = 0 ) There should be extra = sign following is right statement
if ( num % 2 = =0 )

How learning to design programs is like learning to play soccer?

“Learning to design programs is like learning to play soccer. A player must learn to
trap a ball, to dribble with a ball, to pass, and to shoot a ball. Once the player knows
those basic skills, the next goals are to learn to play a position, to play certain
strategies, to choose among feasible strategies, and, on occasion, to create variations
of a strategy because none fits. “

Why we include iostream.h in our programs?

Because standard stream handling function are stored in this file. Before using these
function in our program it is necessary to tell compiler about the location of these functions.

When we declare a multidimensional array the compiler store the elements of multidimensional array in the form of,

►Columns
►Rows
Contiguous memory location
►Matrix

What is the output of the following program?

#include iostream.h
main ( ) {
int RollNo;
int rollno;
RollNo = 5;
rollno = 8;
cout << “Roll No is ” << rollno; }

Program should not compile due to missing <> from following statement
#include iostream.h 
if we ignore this then output should be 
Roll No is 8

We want to access array in random order which approach is better?

Pointers
►Array index
►Both pointers and array index are better
►None of the given options.

Which of the following is an extension of header file?

►.exe
►.txt
►.h ►.c

Which of the following is the starting index of an array in C++?

0 ►1
►-1
►any number

The return type of a function that do not return any value must be __________

►int
void ►double
►float

Call by reference mechanism should be used in a program when there is

i. large amount of data to be passed 
ii. small amount of data to be passed 
iii. need to change the passed data 
iv. no need to change the passed data
Choose the appropriate option for the above case.
► (i) and (ii) only
►(i) and (iii) only
►(ii) and (iii) only
►(ii) and (iv) only

Each pass through a loop is called a/an

►enumeration
iteration 
►culmination
►pass through

The address operator (&) can be used with,

►Statement
►Expression
Variable
►Constant

When a pointer is incremented, it actually jumps the number of memory addresses

According to data type
►1 byte exactly
►1 bit exactly
►A pointer variable can not be incremented

If the elements of an array are already sorted then the useful search algorithm is,

►Linear search
Binary search
►Quick search
►Random search
In binary search algorithm, the ‘divide and conquer’ strategy is  applied. 
This plies only to sorted arrays in ascending or descending order.

C++ views each file as a sequential stream of________________ .

Bytes
►Bits
►0’s or 1’s
►Words

The correct syntax of do-while loop is,

►(condition ) while; do { statements; };
►{ statements; } do-while ();
►while(condition); do { statements; };
do { statements; } while (condition);

In flow chart, the symbol used for decision making is,

►Rectangle 
►Circle 
►Arrow
Diamond
http://www.ehow.com/about_5081911_symbols-used-flowchart.html

&& is _________ operator.

►An arithmetic
Logical ►Relational 
►Unary
we use logical operators ( && and || ) for AND and OR respectively with relational
operators.

In C/C++ the #include is called

►Header file 
Preprocessor Directive 
►Statement 
►Function

There are mainly_________ types of software

Two 
►Three 
►Four 
►Five
Software is categorized into two main categories 
o System Software 
o Application Software

What will be the output of the following segment of C++ code?

int A[5] = {1 , 2, 3, 4};
int i;
for (i=0; i<5; i++)
{
A[i] = 2*A[i];
cout << A[i] << "  ";
}
2 4 6 8 0
Loops will run 5 times as its starting from zero. It will multiply the value of each item in array as
last time is not initialized so it will multiply it with zero to give zero as output

Write down the output of the following code?

int array[7], sum = 0;
for(int i=0;i<7;i++)
{
array[i] = i;
sum+= array[i];
}
cout<< “ Sum = “ <<sum;


Loop will run  times starts from zero and add values from 1 to 6 which is equal to 21

Write a declaration statement for an array of 10 elements of type float. Include an initialization statement of the first four elements to 1.0, 2.0, 3.0 and 4.0.

float tmp [10] = {1.0,2.0,3.0,4.0};

What is the result of the expression x = 2 + 3 * 4 – 4 / 2

first multiplies 3*4 = 12 then Division  4/2 = 2
2+12-2 = 12

To Which category of the software “Compiler and Interpreter” belongs?

They belong to system software.
There are two type of system software
1.  Operating system
2.  Language translators.
These are part of language translators

What's wrong with this for loop? for (int k = 2, k <=12, k++)

► the increment should always be ++k
► the variable must always be the letter i when using a for loop
► there should be a semicolon at the end of the statement
the commas should be semicolons

For which array, the size of the array should be one more than the number of elements in an array?

► int
► double
► float 
char

Which of the following header file defines the rand() function?

► iostream.h
► conio.h
stdlib.h
► stdio.h
The function is rand() and is in the standard library. To access this function, we need to include
<stdlib.h> library in our program. This function will return a random number. The number can
be between 0 and 32767

Commenting the code _____________________

Makes a program easy to understand for others.
► Make programs heavy, i.e. more space is needed for executable.
► Makes it difficult to compile
► All of the given options.

How many bytes are occupied by declaring following array of characters? char str[] = “programming”;

► 10
► 11
12
► 13
11 plus one for null char (11+1= 12)

Which character is inserted at the end of string to indicate the end of string?

► new line
► tab
null
► carriage return
null character inserted at the end of the string by C automatically

Which character is inserted at the end of string to indicate the end of string?

Which looping process is best, when the number of iterations is known?

► for
while
► do-while
► all looping processes require that the iterations be known

Wednesday 1 December 2010

Which of the following can not be a variable name?

► area
► _area
10area
► area2

Which looping process is best, when the number of iterations is known?

Pointer is a variable which store

► Data
Memory Address 
► Data Type
► Values

Preprocessor program perform its function before ______ phase takes place.

► Editing
► Linking
Compiling
► Loading
The C preprocessor modifies a source code file before handing it over to the compiler. You're
most likely used to using the preprocessor to include files directly into other files,

Which of the following function(s) is/are included in stdlib.h header file?

► double atof(const char *nptr)
► int atoi(const char *nptr)
► char *strcpy ( char *s1, const char *s2)
1 and 2 only

Dealing with structures and functions passing by reference is the most economical method

True
► False

Initialization of variable at the time of definition is

► Must
► Necessary
Good Programming
► None of the given options

In if structure the block of statements is executed only

► When the condition is false
► When it contain arithmetic operators
► When it contain logical operators
When the condition is true

The Compiler of C language is written in

► Java Language
► UNIX
► FORTRON Language
C Language

A precise sequence of steps to solve a problem is called

► Statement
Program
► Utility
► Routine

Write a function BatsmanAvg which calculate the average of a player (Batsman), Call this function in main program (Function). Take the input of Total Runs made and Total number of matches played from the user in main function.

#include <iostream.h> // allows program to output data to the screen
// function main begins program execution
int BatsmanAvg(int TotalRuns, int TotalMatches) ;
main()
{
int stopit;
int TotalRuns, TotalMatchesPlayed =0;
cout << "Please Entere the total Runs made : " ;
cin>> TotalRuns ;
cout << "Please Entere the total match played : " ;
cin>> TotalMatchesPlayed ;
cout << "\n Avg Runs = " << BatsmanAvg(TotalRuns,TotalMatchesPlayed);
cin>> stopit; //pause screen to show output

}
int BatsmanAvg(int TotalRuns, int TotalMatches)
{
return TotalRuns/TotalMatches; 
}

If int array[10]; is an integer array then write the statements which will store values at Fifth and Ninth location of this array,

arrary[4] = 200;
arrary[8] = 300;

Identify the errors in the following code segment and give the reason of errors. main(){ int x = 10 const int *ptr = &x ; *ptr = 5 ; }

 *ptr = 5;

What is the difference between switch statement and if statement?

The if statement is used to select among two alternatives. It uses a boolean expression
to decide which alternative should be executed. The switch statement is used to select
among multiple alternatives. It uses an int expression to determine which alternative
should be executed.

Give the syntax of opening file ‘myFile.txt’ with ‘app’ mode using ofstream variable ‘out’.

out.open(“myfile.txt” , ios::app);

Which programming tool is helpful in tracing the logical errors?

Debugger is used to debug the program i.e. to correct the

Paying attention to detail in designing a program is _________

► Time consuming
► Redundant
Necessary
► Somewhat Good
In programming, the details matter.This is a very important skill.A good programmer
always analyzes the problem statement very carefully and in detail.You should pay
attention to all the aspects of the problem.

Analysis is the _________ step in designing a program

► Last
► Middle
► Post Design
First analysis will be always followed by design and then code

The ________ statement interrupts the flow of control.

► switch
► continue
► goto
break

Which of the following operator is used to access the value of variable pointed to by a pointer?

* operator
► -> operator
► && operator
► & operator

If there are 2^(n+1) elements in an array then what would be the number of iterations required to search a number using binary search algorithm?

► n elements
► (n+1) elements
► 2(n+1) elements
► 2^(n+1)elements

How many bytes will the pointer intPtr of type int move in the following statement? intPtr += 3 ;

► 3 bytes
► 6 bytes
12 bytes
► 24 bytes
one int is 4 bytes so 4*3 = 12 bytes movement.

What will be the correct syntax to initialize all elements of two-dimensional array to value 0?

► int arr[2][3] = {0,0} ;
int arr[2][3] = {{0},{0}} ;
► int arr[2][3] = {0},{0} ;
► int arr[2][3] = {0} ;

Consider the following code segment. What will the following code segment display? int main(){ int age[10] = {0}; cout << age ;}

► Values of all elements of array
► Value of first element of array
Starting address of array
► Address of last array element

What is the correct syntax to declare an array of size 10 of int data type?

► int [10] name ;
► name[10] int ;
int name[10] ;
► int name[] ;

A continue statement causes execution to skip to

► the return 0; statement
► the first statement after the loop
► the statements following the continue statement
the next iteration of the loop
continue statement is used, when at a certain stage, you don’t want to execute the
remaining statements inside your loop and want to go to the start of the loop.

Each pass through a loop is called a/an

► enumeration
Iteration
► culmination
► pass through

For which values of the integer _value will the following code becomes an infinite loop? int number=1; while (true) { cout << number; if (number == 3) break; number += integer_value; }

► any number other than 1 or 2
only 0 
► only 1
► only 2
Rational:
number += integer_value
above line decide the fate of loop so any thing other then zero leads to value of 3 which
will quite the loop. Only zero is the value which keeps the loop infinite.

Word processor is

► Operating system
Application software
► Device driver
► Utility software

How many parameter(s) function getline() takes?

► 0
► 1
► 2
► 3
inFile.getLine(name, maxChar, stopChar); The first argument is a character array, the
array should be large enough to hold the complete line. The second argument is the
maximum number of characters to be read. The third one is the character if we want to
stop somewhere.

In C/C++ language the header file which is used to perform useful task and manipulation of character data is

► cplext.h
ctype.h
► stdio.h
► delay.h

The function of cin is

► To display message
To read data from keyboard
► To display output on the screen
► To send data to printe