Uploaded by anasm8931

sadaf anwar assignment pf theory

advertisement
NATIONAL UNIVERSITY OF MODERN TECHNOLOGY (NUML)
ASSIGNMENT:
1
SUBMITTED TO:
MS. SADAF ANWAR
SUBMITTED BY:
ANAS JAHANGIR
SYSTEM ID:
NUML- S21-34263
DATE:
21-03-2021
TASK 1.
Compute and display the total cost of apples given the number of apples purchased is 10 and
cost per apple is 5Rs.
DEFINING AND ANALYZING THE PROBLEM:The number of apple purchase is 10 and cost per apple is 5.we have to multiply the total
apples with cost per apple to get total cost of apples and then print on the screen
DESIGNING THE ALGORITHM :Step 1: start.
Step 2: input per apple cost, total apples.
Step 3: calculate total rupees=per apple cost*total apples.
Step 4: print total rupees.
Step 5: end.
CODING :#include <iostream>
using namespace std;
int main()
{int per_apple=5,total_apples=10;
int total;
total=per_apple *total_apples;
cout<<"total cost is: "<<total;
return 0;
}
Testing the program:-
TASK 2.
Obtain three positive numbers from keyboard and determined and display there sum.
DEFINING AND ANALYZING THE PROBLEM:We has to take three numbers from the user . Add the three numbers and then print on the
screen
DESIGNING THE ALGORITHM :Step 1: start.
Step 2: get input a,b,c.
Step 3: calculate sum =a+b+c.
Step 4: print sum of positive numbers
Step 5: end
FLOWCHART:-
start
Input a,b,c
Sum+a+b+c
Print sum of
number
end
Coding:#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"A is ";
cin>>a;
cout<<"B is ";
cin>>b;
cout<<"c is ";
cin>>c;
int sum=a+b+c;
cout<<"sum of number: "<<sum;
return 0; }
Testing the program:-
Task 3:Different between flowchart and algorithm
flowchart
Algorithm
1. Flowchart is a diagram created by different shapes 1. Algorithm is step by step procedure to solve the
to show the flow of data.
problem.
2. Easy to create and be understood by any person.
2. It is relatively difficult to be understood by a
layman.
3. It uses various kinds of geometrical diagrams
which are interlinked with arrows or lines.
3. Algorithm does not fuse any kind of geometrical
figure.
4. Easy to debug errors
4. Difficult to debug errors
5. Solution is shown in graphical format.
5. Solution is shown in non computer language.
6. Flowchart follows rules to be constructed.
6. algorithm doesnot follow any rule
7. Based on general thoughts and first planning
ideas.
7. Initiated with the help of a flow chart
Task 4:Difference between procedural and non-procedural languages
Procedural language
Non- procedural language
1. Procedural language tells the computer “what to
do” and “how to do”.
It only tells “what to do”
2. Require large number of procedural instructions
Require small number of instructions
3. It is typically file oriented
It is typically data base oriented
4. Size of program written in procedural language is Size of program written in non-procedural language is
large
small
5. Iterative loops and recursive calls both are used
in that language
Only recursive calls
6. Overall efficiency is very high
Overall efficiency is low as compare to procedural
language
7. It is not suitable for time critical time critical
application
8. Difficult to learn and to debug
It is suitable for critical application
9. It returns only restricted data type and allowed
values
10. It works through the state of machine
It can return only data type and value
East to learn and debug
It works through the mathematical function
11. It is command-driven language
It is a function driven language
12. Example: fortron,cobol ,c language,basic
(beginner-all-purpose-symbolic language) etc.
Example: Java, C++,SQL(Structured Query
Language),RGP( report program generator) etc.
Task 5:Difference between compiler and interpreter
compiler
1. Compiler scans the whole program in one go.
2. Compliers generates intermediate machine
code.
3. Display all errors after, compilation, all at the
same time.
4. It is best suited for the Production Environment.
5. Main advantage of compilers is it’s execution
time.
6. It does not require source code for later
execution.
interpreter
Translates program one statement at a time.
Interpreter never generate any intermediate machine
code.
Displays all errors of each line one by one.
It is best suited for the program and development
environment.
Due to interpreters being slow in executing the
object code, it is preferred less.
It requires source code for later execution.
The interpreter requires less memory because there is
7. The compiler need more memory to create an
no such process of creating an object code.
Intermediate object code.
8. It is based on language translation linking-loading It is based on Interpretation Method.
model.
9. Example:
Example:
C,C++,C#, Scala, Java all use complier etc.
PHP, Perl, Ruby uses an interpreter etc.
Task 6:Difference between low-level and high-level programing
Low –level programing language
1. High-Level Languages are easy to learn and
understand.
High-level programing langauge
Low-Level Languages are challenging to learn and
understand.
2. Debugging and maintenance are easier in a high- Debugging and maintenance are not easier in a lowlevel language.
level language.
3. For writing programs, hardware knowledge is not For writing programs, hardware knowledge is a must.
required.
It is more memory efficient.
4. It is less memory efficient.
5. They are executed slower than lower level
languages because they require a translator
program.
6. The high-level code can run all the platforms, so
it is a portable language.
They execute with high speed.
7. High-level languages are much easier and more
flexible to handle than low-level languages.
This flexibility is absent in low-level languages and is
difficult and inflexible to handle.
8. It is programmer friendly language.
9. It is used widely for programming.
The machine code cannot run on all machines, so it is
not a portable language.
It is a machine friendly language.
It is not commonly used now-a-days in programming.
10. Example: BASIC, Perl, Pascal, COBOL, Ruby etc. Example: Machine language and Assembly language
etc.
Download