Showing posts with label Ds malik. Show all posts
Showing posts with label Ds malik. Show all posts

Wednesday, 25 February 2015

C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN (Chapter 1)

Question 1- Mark the following statements as True or False.

a.The first device known to carry out calculations was the Pascaline. FALSE

b.Modern-day computers can accept spoken-word instructions but cannot imitate human reasoning.FALSE



c. In ASCII coding, every character is coded as a sequence of 8 bits. TRUE

d. A compiler translates a high-level program into assembly language. TRUE

e. The arithmetic operations are performed inside CPU, and if an error is found, it outputs the logical errors. FALSE

f. A sequence of 0s and 1s is called a decimal code. FALSE

g. A linker links and loads the object code from main memory into the CPU for execution.TRUE

h. Development of a C++ program includes six steps.TRUE

i. A program written in a high-level programming language is called a source program. TRUE

j. ZB stands for zero byte. FALSE

k. The first step in the problem-solving process is to analyze the problem. TRUE

l. In object-oriented design, a program is a collection of interacting functions. FALSE



2. Name two input devices.
 Ans: Keyboard , Mouse 


3. Name two output devices.

Ans: Monitor, LCD and Printer


4. Why is secondary storage needed?

Ans: 


5. What is the function of an operating system?

Ans: 


6. What are the two types of programs?


Ans: 

7. What are the differences between machine languages and high-level languages?


Ans: 

8. What is a source program?


Ans: 

9. Why do you need a compiler?


Ans: 

10. What kind of errors are reported by a compiler?


Ans: 

11. Why do you need to translate a program written in a high-level language into machine language?


Ans: 

12. Why would you prefer to write a program in a high-level language rather than a machine language?


Ans: 

13. What is linking?


Ans: 

14. What are the advantages of problem analysis and algorithm design over directly writing a program in a high-level language?

Ans: 

15. Design an algorithm to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:

testscore1 weight1
...
For example, sample data is as follows:
75 0.20
95 0.35
85 0.15
65 0.30

Ans: 


16. Design an algorithm to convert the change given in quarters, dimes, nickels, and pennies into pennies.


Ans: 


17. Given the radius, in inches, and price of a pizza, design an algorithm to find the price of the pizza per square inch.


Ans: 


18. A salesperson leaves his home every Monday and returns every Friday. He travels by company car. Each day on the road, the salesperson records the amount of gasoline put in the car. Given the starting odometer reading (that is, the odometer reading before he leaves on Monday) and the ending odometer reading (the odometer reading after he returns home on Friday), design an algorithm to find the average miles per gallon. Sample data is as follows:

68723 71289 15.75 16.30 10.95 20.65 30.00

Ans: 


19. To make a profit, the prices of the items sold in a furniture store are marked up by 60%. Design an algorithm to find the selling price of an item sold at the furniture store. What information do you need to find the selling price?


Ans: 


20. Suppose a, b, and c denote the lengths of the sides of a triangle. Then the area of the triangle can be calculated using the formula: ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi

sðs _ aÞðs _ bÞðs _ cÞ
p
;
where s = (1/2)(a + b + c). Design an algorithm that uses this formula to find the area of a triangle. What information do you need to find the area?

Ans: 


21. Suppose that the cost of sending an international fax is calculated as follows:

Service charges
$3.00; $.20 per page for the first 10 pages; and $0.10 for each additional page. Design an algorithm that asks the user to enter the number of pages to be faxed. The algorithm then uses the number of pages to be faxed to calculate the amount due.

Ans: 


22. An ATM allows a customer to withdraw a maximum of $500 per day. If a customer withdraws more than

$300, the service charge is 4% of the amount
over
$300. If the customer does not have sufficient money in the account, the
ATM informs the customer about the insufficient fund and gives the option to withdraw the money for a service charge of
$25.00. If there is no money in the account or if the account balance is negative, the ATM does not allow the customer to withdraw any money. If the amount to be withdrawn is greater than
$500, the ATM informs the customer about the maximum amount that can be withdrawn. Write an algorithm that allows the customer to enter the amount to be withdrawn. The algorithm then checks the total amount in the account, dispenses the money to the customer, and debits the account by the amount withdrawn and the service charges, if any.

Ans: 


23. You are given a list of students’ names and their test scores. Design an algorithm that does the following:

a. Calculates the average test scores.
b. Determines and prints the names of all the students whose test scores are below the average test score.
c. Determines the highest test score.
d. Prints the names of all the students whose test scores are the same as the highest test score.
(You must divide this problem into sub problems as follows: The first sub problem determines the average test score. The second sub problem determines and prints the names of all the students whose test scores are below the average test score. The third sub problem determines the highest test score. The fourth sub problem prints the names of all the students whose test scores are the same as the highest test score. The main algorithm combines the solutions of the sub problems.)
 
 

Read More

Thursday, 8 January 2015

C plus plus Pattern # 12

Leave a Comment

Code:

#include<iostream>
using namespace std;
void main()
{
for(int i = 1;i<=5;i++)
{
for(int j = 1;j<=i;j++)
{
cout<<j;
}
cout<<endl;
}
}

Output:


Read More

C plus plus Pattern # 11

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
for(int i = 1;i<=5;i++)
{
for(int j = 1;j<=i;j++)
{
cout<<j;
}
cout<<endl;
}
}

Output:



Read More

C plus plus Pattern # 10

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
for(int i = 1;i<=5;i++)
{
for(int j = 1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
}

Output:


Read More

C plus plus Pattern # 9

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
int squre = 4;
for(int i = squre;i>=0;i--)
{
for(int j = squre;j>=0;j--)
{
cout<<char(65+j);
}
cout<<endl;
}
}


Output:


Read More

C plus plus Pattern # 7

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
int squre = 5;
for(int i = squre;i>0;i--)
{
for(int j = squre;j>0;j--)
{
cout<<j;
}
cout<<endl;
}
}


Output:



Read More

C plus plus Pattern # 6

Leave a Comment
Code:

#include<iostream>
using namespace std;
void main()
{
int squre = 5;
for(int i = squre;i>0;i--)
{
for(int j = squre;j>0;j--)
{
cout<<i;  //type casting (int to char)
}
cout<<endl;
}

}

Output:



Read More

Sunday, 19 October 2014

c plus plus Reserved words

Leave a Comment

Reserved words

The syntax rules (or grammar) of C++ define certain symbols to have a unique meaning within a C++ program. These symbols, the reserved words, must not be used for any other purposes. The reserved words already used are int and void. All reserved words are in lower-case letters. The table below lists the reserved words of C++. C++ Reserved Words
and
and_eq
asm


bitor
bool
break


char
class
const


default
delete
do


else
enum
explicit


false
float
for


if
inline
int


namespace
new
not


or
or_eq
private


register
reinterpret_cast
return


sizeof
static
static_cast


template
this
throw


typedef
typeid
typename


using
virtual
void


while
xor
xor_eq
auto
bitand

case
catch

const_cast
continue

double
dynamic_cast

export
extern

friend
goto

long
mutable

not_eq
operator

protected
public

short
signed

struct
switch

true
try

union
unsigned

volatile
wchar_t



Some of these reserved words may not be treated as reserved by older compilers. However you would do well to avoid their use. Other compilers may add their own reserved words. Typical are those used by Borland compilers for the PC, which add nearfarhugecdecl, and pascal.
Notice that main is not a reserved word. However, this is a fairly technical distinction, and for practical purposes you are advised to treat maincin, and cout as if they were reserved as well.
Read More

Ds Malik Chapter 2 Question 2

Leave a Comment
1.       Which of the following are valid C++ identifiers?

a.            myFirstProgram                                      Valid
b.            MIX-UP                                                  Valid
c.             C++Program2                                        In Valid
d.            quiz7                                                       Valid
e.            ProgrammingLecture2                            Valid
f.             1footEquals12Inches                              in Valid
g.            Mike'sFirstAttempt                                 in Valid
h.            Update Grade                                          in Valid
i.             4th                                                          in Valid

j.             New_StudenT                                         Valid
Read More

Saturday, 4 October 2014

2. Which of the following are valid C++ identifiers? ds malik Chapter-2

1 comment
2. Which of the following are valid C++ identifiers?

a. myFirstProgram    VALID
b. MIX-UP                INVALID
c. C++Program2       INVALID
d. quiz7                     VALID
e. ProgrammingLecture2    VALID         
f. 1footEquals12Inches       INVALID                          
g. Mike'sFirstAttempt         INVALID

h. Update Grade                  INVALID
i. 4th                                            INVALID
j. New_Student                   VALID
Read More

Ds malik c++ programming Chapter 2-Question-1

Leave a Comment











Solution

1. Mark the following statements as true or false.
a. An identifier can be any sequence of digits and letters.FALSE
b. In C++, there is no difference between a reserved word and a predefined identifier.FALSE
c. A C++ identifier can start with a digit.FALSE
d. The operands of the modulus operator must be integers.TRUE
e. If a = 4; and b = 3;, then after the statement a = b; the value of b is still 3.TRUE
f. In the statement cin >> y;, y can only be an int or a double variable.FALSE    
g. In an output statement, the newline character may be a part of the string.TRUE
h. The following is a legal C++ program:TRUE
int main()
{
return 0;
}
i. In a mixed expression, all the operands are converted to floating-point numbers.FALSE
j. Suppose x = 5. After the statement y = x++; executes, y is 5 and x is 6.TRUE
k. Suppose a = 5. After the statement ++a; executes, the value of a is still 5 because the value of the expression is not saved in another variable.FALSE
Read More

Wednesday, 2 July 2014

Chapter#2 Basic Elements of C++











                           Solution







                           Solution

Read More

Chapter#1 An Overview of Computers and Programming Languages

Leave a Comment


Chapter 1: An Overview of Computers and Programming Languages


EXERCISES

1. Mark the following statements as true or false.

a. The first device known to carry out calculations was the Pascaline.

b. Modern-day computers can accept spoken-word instructions but cannot imitate human    reasoning.

c. In ASCII coding, every character is coded as a sequence of 8 bits.

d. A compiler translates a high-level program into assembly language.

e. The arithmetic operations are performed inside CPU, and if an error is found, it outputs the logical errors.

f. A sequence of 0s and 1s is called a decimal code.

g. A linker links and loads the object code from main memory into the CPU for execution.

h. Development of a C++ program includes six steps.

i. A program written in a high-level programming language is called a source program.

j. ZB stands for zero byte.

k. The first step in the problem-solving process is to analyze the problem.

l. In object-oriented design, a program is a collection of interacting functions.

Questions



2. Name two input devices.

3. Name two output devices.

4. Why is secondary storage needed?

5. What is the function of an operating system?

6. What are the two types of programs?

7. What are the differences between machine languages and high-level languages?

8. What is a source program?

9. Why do you need a compiler?

10. What kind of errors are reported by a compiler?

11. Why do you need to translate a program written in a high-level language into machine language?

12. Why would you prefer to write a program in a high-level language rather than a machine language?

13. What is linking?

14. What are the advantages of problem analysis and algorithm design over directly writing a program in a high-level language?

15. Design an algorithm to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:

testscore1 weight1

...

For example, sample data is as follows:

75 0.20

95 0.35

85 0.15

65 0.30

16. Design an algorithm to convert the change given in quarters, dimes, nickels, and pennies into pennies.

17. Given the radius, in inches, and price of a pizza, design an algorithm to find the price of the pizza per square inch.

18. A salesperson leaves his home every Monday and returns every Friday. He travels by company car. Each day on the road, the salesperson records the amount of gasoline put in the car. Given the starting odometer reading (that is, the odometer reading before he leaves on Monday) and the ending odometer reading (the odometer reading after he returns home on Friday), design an algorithm to find the average miles per gallon. Sample data is as follows:

68723 71289 15.75 16.30 10.95 20.65 30.00

19. To make a profit, the prices of the items sold in a furniture store are marked up by 60%. Design an algorithm to find the selling price of an item sold at the furniture store. What information do you need to find the selling price?

20. Suppose a, b, and c denote the lengths of the sides of a triangle. Then the area of the triangle can be calculated using the formula:

ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi

sðs _ aÞðs _ bÞðs _ cÞ

p

; where s = (1/2)(a + b + c). Design an algorithm that uses this formula to find the area of a triangle. What information do you need to find the area?

 21. Suppose that the cost of sending an international fax is calculated as follows:

Service charges

$3.00; $.20 per page for the first 10 pages; and $0.10 for each additional page. Design an algorithm that asks the user to enter the number of pages to be faxed. The algorithm then uses the number of pages to be faxed to calculate the amount due.

22. An ATM allows a customer to withdraw a maximum of $500 per day. If a customer withdraws more than

$300, the service charge is 4% of the amount over

$300. If the customer does not have sufficient money in the account, the

ATM informs the customer about the insufficient fund and gives the option to withdraw the money for a service charge of

$25.00. If there is no money in the account or if the account balance is negative, the ATM does not allow the customer to withdraw any money. If the amount to be withdrawn is greater than

$500, the ATM informs the customer about the maximum amount that can be withdrawn. Write an algorithm that allows the customer to enter the amount to be withdrawn. The algorithm then checks the total amount in the account, dispenses the money to the customer, and debits the account by the amount withdrawn and the service charges, if any.

23. You are given a list of students’ names and their test scores. Design an algorithm that does the following:

a. Calculates the average test scores.

b. Determines and prints the names of all the students whose test scores are below the average test score.

c. Determines the highest test score.

d. Prints the names of all the students whose test scores are the same as the highest test score.

(You must divide this problem into subproblems as follows: The first subproblem determines the average test score. The second subproblem determines and prints the names of all the students whose test scores are below the average test score. The third subproblem determines the highest test score. The fourth subproblem prints the names of all the students whose test scores are the same as the highest test score. The main algorithm combines the solutions of the subproblems.)
Read More