Question 1 a) Describe any two kinds of program errors? b) Explain why the use o
ID: 3603613 • Letter: Q
Question
Question 1 a) Describe any two kinds of program errors? b) Explain why the use of functions is important in programming c) Write a C++ program that reads in three integers, determines and prints the [4 marks] [4 marks] largest and the smallest in the group [6 Marks] d) Consider the pseudocode below Use variables years OF TYPE INTEGER Use variables: sales, wage, loyaltyBonus OF TYPE REAL Use variable salesmanName OF TYPE STRING Begin DISPLAY "Please enter the name of a salesman ACCEPT salesmanName DISPLAY "Please enter sales for this period" ACCEPT sales DISPLAY "Please enter number of years he has spent in this Company" ACCEPT years wage : sales * 0.15 loyalty:Bonus : = wage * 0.1 IF yearS > 3 THEN wage : wage + loyalty-Bonus ENDIF DISPLAY salesmanNameearns " wage End [2 marks] i. What does the above pseudocode do? ii What would be displayed on the screen if the system user entered P3000 for sales, Paul Fisherman as salesman's name and 4 years for number of years spent? Write a C++ program to depict the above algorithm. 2 marks] 17 marks] iii.Explanation / Answer
a)
Syntax Error
A syntax error is an error in the source code of a program. Since computer programs must follow strict syntax to compile correctly, any aspects of the code that do not confirm to the syntax of the programming language will produce a syntax error.
example:
1) which errors in the flow or logic of a program.
2) syntax errors are small grammatical mistakes.
Logical Error
A logic error (or logical error) is a mistake in a program's source code that results in incorrect or unexpected behavior. It is a type of runtime error that may simply produce the wrong output or may cause a program to crash while running
example:
Incorrect: if ($i=1) { ... }
Correct: if ($i==1) { ... }
b)
importance of function
Function prototype tells compiler about number of parameters function takes, data-types of parameters and return type of function. By using this information, compiler cross checks function parameters and their data-type with function definition and function call. If we ignore function prototype, program may compile with warning, and may work properly. But some times, it will give strange output and it is very hard to find such programming mistakes.
a) It reduce the time .
b) It reduce the complexity of the program.
C) Take less time for program execution.
c)
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"enter the first no:";
cin>>a;
cout<<" enter the second no:";
cin>>b;
cout<<" enter the third no:";
cin>>c;
cout<<"larget number is:";
if((a>b)&& (a>c))
{
cout<<a;
}
else
if((b>c)&& (b>a))
{
cout<<b;
}
else
if((c>b)&& (c>a))
{
cout<<c;
}
cout<<"smallest number is:";
if((a<b)&& (a<c))
{
cout<<a;
}
else
if((b<c)&& (b<a))
{
cout<<b;
}
else
if((c<b)&& (c<a))
{
cout<<c;
}
getch();
}
d)
1) It display the wages earned by the salesman.
2)wages=3000*0.15=450
bonus=450*0.1=45
now
year=4
then
wages=450+45=445
on screen it display the result is:
PaulFisherman earns 450 wages.
3)
#include<iostream.h>
#include<conio.h>
void main()
{
int years;
real sales,wages,bonus;
char salesmanname[20];
cout<<"please enter the salesmanname:";
cin>>salesmanname;
cout<<" enter the sales for this period:";
cin>>sales;
cout<<" enter the number of years he has spent in this year:";
cin>>year;
wages = sales*0.15;
bonu = wages*0.1;
if(years>3)
wages = wages + bonus ;
cout<<" salesman earn wages:"<<wages;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.