{"id":45533,"date":"2024-02-19T05:40:54","date_gmt":"2024-02-19T00:10:54","guid":{"rendered":"https:\/\/www.aplustopper.com\/?p=45533"},"modified":"2024-02-19T11:23:51","modified_gmt":"2024-02-19T05:53:51","slug":"plus-one-computer-application-chapter-wise-questions-answers-chapter-5","status":"publish","type":"post","link":"https:\/\/www.aplustopper.com\/plus-one-computer-application-chapter-wise-questions-answers-chapter-5\/","title":{"rendered":"Plus One Computer Application Chapter Wise Questions Chapter 5 Data Types and Operators"},"content":{"rendered":"
Question 1.
\n________ is the main activity carried out in computers
\nAnswer:
\nData processing<\/p>\n
Question 2.
\nThe data used in computers are different. To differentiate the nature and size of data _____is used.
\nAnswer:
\nData types<\/p>\n
Question 3. Question 4. Question 5. Question 6. Question 7. Question 8. Question 9. Question 10. Question 11. Question 12. Question 13. Question 14. Question 15. Question 16. Question 17. Question 18. Question 19. Question 20. Question 21. Question 22. Question 23. Question 24. Question 25. Question 26. Question 27. Question 28. Question 29. Question 30. Question 31. Question 32. Question 33. Question 1. Question 2. Question 3. Question 4. Question 5. Question 6. Question 7. Question 8. Question 9. Question 10. Question 11. Question 12. Question 13. Question 14. Question 15. Question 16. Question 17. Question 18. Question 19. Question 20. Question 21. Question 22. Question 23. Question 24. Question 25. Question 26. Question 27. Question 28. Question 29. Question 30. Question 31. Question 1. Question 2. Question 3. 1) The size of RHS is less than LHS. So there is no problem and RHS data type is promoted to LHS. Here it is compatible. Question 4. Question 5. Predict the type of errors during compilation, execution and verification of the output. Also write the output of two sets of input values Question 6. ii) char data type :-<\/strong> Any symbol from the key board, eg. ‘A’ , ‘?’, ‘9’, It consumes one byte( 8 bits) of memory. It is internally treated as integers, i.e. 28 = 256 characters. Each character is having a ASCII code, ‘a’ is having ASCII code 97 and zero is having ASCII code 48.<\/p>\n iii) float data type:-<\/strong> It is used to store real numbers i.e. the numbers with decimal point. It uses 4 bytes(32 bits) of memory. Eg. 67.89, 89.9 E-15.<\/p>\n iv) double data type:-<\/strong> It is used to store very large real numbers. It uses 8 bytes(64 bits) of memory.<\/p>\n v) void data type :-<\/strong> void means nothing. It is used to represent a function returns nothing.<\/p>\n Question 7. Question 8. Question 9. Question 10. Question 11. ii) char data type:<\/strong> Any symbol from the key board, iii) float data type:<\/strong> It is used to store real numbers i.e. the numbers with decimal point. It uses 4 bytes(32 bits) of memory. Eg. 67.89, 89.9 E-15.<\/p>\n iv) double data type:<\/strong>\u00a0It is used to store very large real numbers. It uses 8 bytes(64 bits) of memory.<\/p>\n v) void data type:<\/strong> void means nothing. It is used to represent a function returns nothing. Question 12. Question 13. Question 14. Question 15. Question 1. ii) char data type:\u00a0<\/strong>Any symbol from the key board, iii) float data type:<\/strong>\u00a0It is used to store real numbers i.e. the numbers with decimal point. It uses 4 bytes(32 bit?) of memory. iv) double data type:<\/strong>\u00a0It is used to store very large real numbers. It uses 8 bytes(64 bits) of memory.<\/p>\n v) void data type :<\/strong>\u00a0void means nothing. It is used to represent a function returns nothing.<\/p>\n Question 2. x\/y = 3, because both operands are integer, “to get the floating point result one of the operand must be float. 6) sizeof( ):<\/strong> This operator is used to find the size used by each data type. 7) Increment and decrement operator:<\/strong>\u00a0 These are unary operators.<\/p>\n a) Increment operator (++):<\/strong> It is used to increment the value of a variable by one i.e., x++ is equivalent to x=x+1; 8) Assignment operator (=) :<\/strong> lt is used to assign the value of a right side to the left side variable.eg. x=5; Here the value 5 is assigned, to the variable x.<\/p>\n Kerala\u00a0Plus One Computer Application Chapter Wise Questions\u00a0 Chapter 5 Data Types and Operators Plus One Computer Application Data Types and Operators 1 Mark Questions and Answers Question 1. ________ is the main activity carried out in computers Answer: Data processing Question 2. The data used in computers are different. To differentiate the nature and size […]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[42728],"tags":[],"yoast_head":"\n
\nClassify the following data types.
\nint
\narray
\nfunction
\nchar
\npointer
\nvoid
\nfloat
\ndouble
\nstructure
\nAnswer:
\nFundamental data types<\/strong>
\nint
\nfloat
\ndouble
\nvoid
\nchar
\nDerived data types<\/strong>
\narray
\nfunction
\npointer
\nstructure<\/p>\n
\nSheela wants to store her age. From the following which is the exact data type.
\na) void
\nb) char
\nc) int
\nd) double
\nAnswer:
\nc) int<\/p>\n
\nInteger data type uses Integer data type ;
\na) 5
\nb) 2
\nc) 3
\nd)4
\nAnswer:
\nd)4<\/p>\n
\nchar data type uses ______ bytes of memory
\na) 1
\nb) 3
\nc) 7
\nd) 8
\nAnswer:
\na)1<\/p>\n
\nFrom the following which data type uses 4 bytes of memory
\na) float
\nb) short
\nc) char
\nd) double
\nAnswer:
\na) float<\/p>\n
\nExpand ASCII _______.
\nAnswer:
\nAmerican Standard Code for Information Inter-change<\/p>\n
\nRamu wants to store the value of From the fol-lowing which is correct declaration
\na) char pi=3.14157
\nb) int pi=3.14157
\nc) float pi=3.14157
\nd) long pi=3.14157
\nAnswer:
\nc) float pi=3.14157<\/p>\n
\nFrom the following which is not true , to give a variable name.
\na) Starting letter must be an alphabet
\nb) contains digits
\nc) Cannot be a key word
\nd) special characters can be used
\nAnswer:
\nd) special characters can be used<\/p>\n
\nPick a valid variable name from the following
\na) 9a
\nb) float
\nc)age
\nd) date of birth
\nAnswer:
\nc)age<\/p>\n
\nTo perform a unary operation how many number of operands needed?
\na) 2
\nb)3
\nc) 1
\nd) None of these
\nAnswer:
\nc) 1 (Unary means one)<\/p>\n
\nTo perform a binary operation how many number of operands needed?
\na) 2
\nb) 3
\nc) 1
\nd) None of these.
\nAnswer:
\na) 2 (binary means two)<\/p>\n
\nTo perform a ternary operation how many number of operands needed?
\na) 2
\nb) 3
\nc) 1
\nd) None of these.
\nAnswer:
\nb) 3 (eg: ternary means three)<\/p>\n
\nIn C++ 13% 26 =
\na) 26
\nb) 13
\nc) 0
\nd) None of these
\nAnswer:
\n% is a mod operator i.e, it gives the remainder. Here the remainder is 13.<\/p>\n
\nIn C++ 41\/2 =
\na) 20.5
\nb) 20
\nc) 1
\nd) None of these
\nAnswer:
\nb) 20. (The actual result is 20.5 but both 41 and 2 are integers so .5 must be truncated)<\/p>\n
\n++ is a ______ operator
\na) Unary
\nb) Binary
\nc) Ternary
\nd) None of these
\nAnswer:
\na) Unary.<\/p>\n
\nConditional operator is ______ operator
\na) Unary
\nb) Binary
\nc) Ternary
\nd)None of these
\nAnswer:
\nc) Ternary<\/p>\n
\n% is a operator ______.
\na) Unary
\nb) Binary
\nc) Ternary
\nd) None of these
\nAnswer:
\nb) Binary<\/p>\n
\nState true or false:
\na) Multiplication, division, modulus have equal priority.
\nb) Logical and (&&) has less priority than logical or ( )
\nAnswer:
\na) True
\nb) False<\/p>\n
\n_____ is composed of operators and operands.
\na) expression
\nb) Key words
\nIdentifier
\nd) Punctuators
\nAnswer:
\na) expression<\/p>\n
\nSupply value to a variable at the time of declaration is known as _____.
\nAnswer:
\nInitialisation<\/p>\n
\nFrom the following which is initialisation
\na) int k;
\nb)int k=100;
\nc) int k[10];
\nd) None of these
\nAnswer:
\nb) int k=100;<\/p>\n
\nState True \/ False<\/strong>
\nIn an expression all the operands having lower size are converted(promoted) to the data type of the highest sized operand.
\nAnswer:
\nTrue<\/p>\n
\nClassify the following as arithmetic \/ Logical expression
\na) x+y*z
\nb) xz
\nc) x\/y
\nd) x>89 || y<80
\nAnswer:
\na) and c) are Arithmetic
\nb) and d) are Logical<\/p>\n
\nSuppose x=5 and y=2 then what will be cout<<(float) x\/y
\nAnswer:
\n2.5 The integer x is converted to float hence the result.<\/p>\n
\nConsider the following.
\na = 10;
\na =100;
\nThen a =
\na) a = 100
\nb) a = 50
\nc)a = 10
\nd) a = 20
\nAnswer:
\na) a = 100. This short hand means a = a*10<\/p>\n
\nConsider the following.
\na=10 ;
\na+=10;
\nThen a=
\na) a= 30
\nb) a= 50
\nc)a=10
\nd) a=20
\nAnswer:
\nd) a=20. This short hand means a=a+10<\/p>\n
\nPick the odd one out
\na) structure
\nb) Array
\nc) Pointer
\nd) int
\nAnswer:
\nd) int, it is fundamental data type the others are derived data types<\/p>\n
\nFrom the following select not a character of C++ language
\na) A
\nb) 9
\nc)\\
\nd)@
\nAnswer:
\nd)@<\/p>\n
\nConsider the following
\nfloat x=25.56; cout<<(int)x; Here the data type of the variable is converted. What type of conversion is this?
\na) type promotion
\nb) type\u201d casting
\nc) implicit conversion
\nd) None of these
\nAnswer:
\nb) type casting (explicit conversion)<\/p>\n
\nIdentify the error in the following C++ statement and correct it.
\nAnswer:
\nThe maximum number that can store in short type is less than 32767. So to store 68000 we have to use long data type.<\/p>\n
\nConsider the following statements in C++ if(mark>=18)
\ncout<<\u201cPassed\u201d; \u2019
\nelse ,
\ncout<<\u201cFailed\u201d;
\nSuggest an operator in C++ using which the same , output can be produced.
\nAnswer:
\nConditional operator (?:)<\/p>\nPlus One Computer Application Data Types and Operators 2 Marks Questions and Answers<\/h3>\n
\nAnalyses the following .statements and write True or False. Justify
\ni) There* is an Operator in C++ having no special character in it
\nii) An operator cannot have more than 2 operands
\niii) Comma operator has the lowest precedence
\niv) All logical operators are binary in nature
\nv) It is not possible to assign the constant 5 to 10 different variables using a single C++ expression
\nvi) In type promotion the operands with lower data , type will be converted to the highest data type in expression.
\nAnswer:
\ni) True (size of operator)
\nii) False( conditional operator can have 3 operands
\niii) True
\niv) False
\nv) False(Multiple assignment is possible,
\neg: a=b=c=…..= 5
\nvi) True<\/p>\n
\nConsider the following declaration.
\nconst int bp;
\nbp = 100;
\nIs it valid? Explain it?
\nAnswer:
\nThis is not valid. This is an error. A constant variable cannot be modified. That is the error and a constant variable must be initialised. So the correct declaration js as follows, const int bp=100;<\/p>\n
\nConsider the following statements in C++
\n1) cout<<41\/2;
\n2) cout<<41\/2.0; Are this two statements give same result? Explain?
\nAnswer:
\nThis two statements do not give same results. The first statement 41\/2 gives 20 instead of 20.5. The reason is 41 and 2 are integers. If two operands are integers the result must be integer, the real part must be truncated. To get floating result either one of the operand must be float. So the second statement gives 20.5. The reason is 41 is integer but 2.0 is a float.<\/p>\n
\nIf mark = 70 then what will be the value of variable result in the following result = mark > 50 ? \u2019P\u2019: ‘F’;
\nAnswer:
\nThe syntax of the conditional operator is given below Condition? Value if true: Value if false;
\nHere the conditional operator first checks the condition i.e.,70>50 it is true. So ‘P’ is assigned to the variable result.
\nSo the result is ‘P’<\/p>\n
\nIs it possible to initialise a variable at the time of execution. What kind of initialisation is this? Give an example
\nAnswer:
\nYes it is possible. This is known as Dynamic initialisation.. The example is given below
\nEg: int a=10,b=5;
\nint c=a*b;
\nhere the variable c is declared and initialised with the value 10*5.<\/p>\n
\nBoolean data type is used to store True \/ False in C++. Is it true? Is there any data type Called Boolean in C++?
\nAnswer:
\nNo there is no data type for storing boolean value true \/ false.
\nBut in C++ non -zero (either negative or positive) is treated as true and zero is treated as false.<\/p>\n
\nConsider the following
\nn=-15;
\nif (n)
\ncout<<“Hello”;
\nelse
\ncout<<“hai”;
\nWhat will be the output of the above code?
\nAnswer:
\nThe Output is Hello, because n = – 15 a non zero number and it is treated as true hence the result.<\/p>\n
\nIs it possible to declare a variable in between the program as and when the need arise.? Then what is it?
\nAnswer:
\nYes it is possible to declare a variable in between the program as and when the need arise. It is known as dynamic initialisation.
\nEg. int x=10,y=20;
\n…………..;
\n…………
\nint z=x*y<\/p>\n
\nchar ch;
\ncout<<“Enter a character”; cin>>ch;
\nConsider the above code, a user gives 9 to the variable ‘ch’. Is there any problem? Is it valid?
\nAnswer:
\nThere is no problem and it is valid since 9 is a character. Any symbol from the key board is treated as a character.<\/p>\n
\n“With the same size we can change the sign and range of data”. Comment on this statement.
\nAnswer:
\nWith the help of type modifiers we can change the sign and range of data with same size. The important modifiers are signed, unsigned, long and short.<\/p>\n
\nWrite short notes about C++ short hands?
\nAnswer:
\nx=x + 10 can be represented as x+=10, It is called short hands in C++. It is faster.
\nThis is used with all the arithmetic operators as follows.
\n<\/p>\n
\nWhat is the role of ‘const’ modifier? \u2018
\nAnswer:
\nThis ‘const’ key word is used to declare a constant, Eg. const int bp=100;
\nBy this the variable bp is treated as constant and cannot be possible to change its value during execution.<\/p>\n
\nSpecify the most appropriate data type for handling the following data.
\ni) Rollno. of a student.
\nii) Name of an employee.
\niii) Price of an article.
\niv) Marks of 12 subjects
\nAnswer:
\ni) short Rollno;
\nii) char name[20];
\niii) float price;
\niv) short marks[12j;<\/p>\n
\nWrite C++ statement for the following.
\na) The result obtained when 5 is divided by 2.
\nb) The. remainder obtained when 5 is divided by 2.
\nAnswer:
\na) 5\/2
\nb) 5%2<\/p>\n
\nPredict the output.justify
\nint k = 5,
\nb = 0;
\nb = k++ + ++k;
\ncout<<b;
\nAnswer:
\nOutput is 12. In this statement first it take the value of k in 5 then increment it K++. So first operand for + is 5. Then it becomes 6. Then ++k makes it 7. This is the second operand. Hence the result is 12.<\/p>\n
\nPredict the output.
\na) int sum = 10, ctr = 5;
\nsum = sum + ctr –;
\npout<< sum;
\nb) int sum = 10, ctr = 5;
\nsum = sum + ++ctr; cout<<sum;
\nAnswer:
\na)15
\nb) 16<\/p>\n
\nPredict the output.
\nint a; .
\nfloat b; .
\na = 5;
\ncout << sizeof(a + b\/2);
\nAnswer:
\nOutput is 4. Result will be the memory size of floating point number<\/p>\n
\nPredict the output.
\nint a, b, c;
\na = 5; b = 2;
\nc = a\/b;
\ncout<<c; Answer: Output is 2. Both operands are integers. So the result will be an integer.<\/p>\n
\nExplain cascading of i\/o operations
\nAnswer:
\nThe multiple use of input or output operators in a single statement is called cascading of i\/o operators.
\nEg: To fake three numbers by using one statement is as follows cin>>x>>y>>z;
\nTo print three numbers by using one statement is
\nas follows
\ncout<<x<<y<<z;<\/p>\n
\nTrace out and correct the errors in the following code fragments
\ni) cout<<“Mark=\u201d45;
\nii) cin <<“Hellow World!”; iii) cout>>”X + Y;
\niv) Cout<<‘Good'<<‘Moming’
\nAnswer:
\ni) cout<<“Mark=45”;
\nii) cout <<“Hellow World!”;
\niii) cout< iv) Cout<<“Good Morning”;<\/p>\n
\nRaju wants to add value 1 to the variable \u2018p\u2019 and store the new value in \u2018p\u2019 itself. Write four different statements in C++ to do the task.
\nAnswer:
\n1) P=P+1; 2) p++;(post increment) 3) ++p; (pre increment) 4) p+=1; (short hand in C++)<\/p>\n
\nRead the following code: charstr[30]; cin>>str;
\ncout<<str; . If we give the input \u201cGreen Computing\u201d, we get the . output \u201cGreen\u201d. Why is it so? How can you correct that?
\nAnswer:
\nThe input statement cin>> cannot read the space. It reads the text up to the space, i.e. the delimiter is space. To read the text up to the enter key gets( ) or getline( ) is used<\/p>\n
\nMatch the following :
\n
\nAnswer:
\n<\/p>\n
\nWrite a C++ expression to calculate the value of the following equation.
\n\\(x=\\frac{-b+\\sqrt{b^{2}-4 a c}}{2 a}\\)
\nAnswer:
\n<\/p>\n
\nA student wants to insert his name and school address in the C++ program that he has written. But this should not affect the compilation or execution of the program. How is it possible? Give an example.
\nAnswer:
\nHe can use comments to write this information. In C++ comments are used to write information such as programmer\u2019s name, address, objective of the codes etc. in between the actual codes. This is not the part of the programme.
\nThere are two types of comments.
\ni) Single line (\/\/) and ii) Multi line (\/* and *\/)
\ni) Single line (\/\/) :<\/strong> Comment is used to make a single line as a comment. It starts with \/\/.
\nEg : \/\/programme starts here.
\nii) Multi line (\/* and *\/):<\/strong> To make multiple lines as a comment. It starts with \/* and ends with *\/.
\nEg : !* this programme is used to find sum of two numbers.*\/<\/p>\n
\nConsider the following C++ statements :
\nchar word (20]
\ncin>>word;
\ncoUt<<word; gets(word); puts(word); If the string entered is \u201cHAPPY NEW YEAR\u201d, predict the output and justify your answer.
\nAnswer:
\ncin>>word;
\ncout<<word;
\nIt displays \u201cHAPPY\u201d because cin takes characters upto the space. That is space is the delimiter for cin. The string after space is truncated. To resolve this use gets ( ) function. Because gets ( ) function reads character upto the enter key.
\nHence gets (word);
\nputs (word);
\nDisplays \u201cHAPPY NEW YEAR\u201d<\/p>\n
\nWrite the difference between x = 5 and x ==5 in C++.
\nAnswer:
\nx = 5 means the value 5 of the RHs is assigned to the LHS variable x . Here = is the assignment operator. But x ==5, ==this is the relational (comparison) operator. Here it checks whether the value of RHS is equal to the value of LHS and this expression returns a boolean value as a result. It is the equality operation.<\/p>\n
\na) What is the output of the following program?
\n# include
\nvoid main ( )
\n{
\nint a;
\na = 5+3*5;
\ncout << a;
\n}
\nb) How do 9, ‘9\u2019 and \u201c9\u201d differ in C++ program?
\nAnswer:
\nHere multiplication operation has more priority than addition.
\nhence a = 5 + 15 = 20
\nb) Here
\n9 is an interger
\n\u20189\u2019 is an character
\n\u201c9\u201d is a string<\/p>\n
\nRead the following C++ program and predict the output by explaining the operations performed.
\n#include
\nvoid main ( )
\n{
\nint a=5, b=3;
\ncout<<a++ \/–b;
\ncout<<a\/ (float) b; . . }
\nAnswer:
\nHere a = 5 and b = 3 a++ \/ – – b = 5\/2 = 2 That is a++ uses the value 5 and next it changes its value to 6 So a\/(float) b = 6\/(float)2 = 6\/2.0 = 3 So the output, is 2 and 3<\/p>\n
\nWhat is preprocessor directive statement? Explain. with an example.
\nAnswer:
\nA C++ program starts with the pre processor directive i.e., # include, #define, #undef, etc, are such a pre processor directives. By using #include we can link the header files that are needed to use the functions. By using #define we can define some constants.
\nEg. #define x 100. Here the value of x becomes 100 and cannot be changed in the program. No semicolon is needed.<\/p>\n
\nThe following C++ code segment is a part of a program written by Smitha to find the average of 3 numbers. int a, b, c; float avg; cin>>a>>b>>c;
\navg=(a+b+c)\/3; ‘
\ncout<<avg; , What will be the output if she inputs 1, 4 and 5? How can you correct it?
\nAnswer:
\n=(1 +4+5)\/3 =10\/3 =3.3333 Instead of this 3.3333 the output will be 3. This is because if both operands are integers an integer division will be occurred, that is the fractional part will be truncated. To get the correct out put do as follows
\ncase 1: int a,b,c; is replaced by float a,b,c;
\nOR<\/strong>
\ncase 2: Replace (a+b+c)\/3 by (a+b+c)\/3.0;
\nOR<\/strong>
\ncase 3:Type casting. Replace avg=(a+b+c)\/3; by avg=(float)(a+b+c)\/3;<\/p>\nPlus One Computer Application Data Types and Operators 3 Marks Questions and Answers<\/h3>\n
\nIn a panchayath or municipality all the houses have a house number, house name and members. Similar situation is in the case of memory.Explain Answer: The named memory locations are called variable. A variable has three important things 1) variable name : A variable should have a name 2) Memory address : Each and every byte of memory has an address, it is also called location (L) value 3) Content: The value stored in a variable is called content. It is also called Read(R) value.<\/p>\n
\nBriefly explain constants
\nAnswer:
\nA constant or a literal is a data item its value doe not change during execution. The keyword const is used to declare a constant. Its declaration is as follows , const data type variable name=value; eg.const int bp=100; const float pi=3.14157; const char ch=’a’; const ehar[]=”Alvis”; .
\n1) Integer literals :<\/strong> Whole numbers withbut fractional parts are known as integer literals, its value does not change during execution. There are 3 types decimal, octal and hexadecimal. Eg. For decimal 100,150,etc For octal 0100,0240, etc For hexadecimal 0x100, 0x1 A,etc
\n2) Float literals :<\/strong> A number with fractional parts and its value does not change during execution is called floating point literals. Eg. 3.14157,79.78, etc
\n3) Character literal:<\/strong> A valid C++ character enclosed in single quotes, its value does not change during execution. Eg. ‘m’, ‘f’, etc
\n4) String literal<\/strong> One or more characters enclosed in double quotes is called string constant. A string is automatically appended by a null character(‘\\0’) . Eg. “Mary’s”,”India”,etc<\/p>\n
\nConsider the following statements int a=10,x=20; float b=49000.34,y=56.78; i) a=b; ii) y=x; Is there any problem for the above statements? What do you mean by type compatibility?
\nAnswer:
\nAssignment operator is used to assign the value of RHS to LHS. Following are the two chances<\/p>\n
\n2) The size of RHS is higher than LHS. Here comes the problem sometimes LHS cannot possible to assign RHS. There may be a chance of wrong answer. Here it is not compatible.
\nHere
\ni) a=b; There is an error since the size of . LHS is 2 but the size of RHS is 4.
\nii) y=x; There is no problem because the size of LHS is 4 and RHS is 2.<\/p>\n
\nA company has decided to give incentives to their salesman as per the sales. The criteria is given below. If the total sales exceeds 10,000 the incentive is 10% .
\ni) If the total sales >=5,000 and total sales <10,000, the incentive is 6 % ii) If the total sales >=1,000 and total sales <5,000, the incentive is 3 %
\nWrite a C++ program to solve the above prob-lem and print the incentive after accepting the total sales of a salesman. The program code should not make use of ‘if statement. )
\nAnswer:
\n#include
\nusing namespace std;
\nint main( )
\n{
\nfloat sales,incentive;
\ncout<<“enter the sales”; cin>>sales;
\nincentive=(sales>10000 ? salesMO: (sales > =5000 ? sales * .06 : (sales >= 1000 ? sales * .03: 0)>>;
\ncout<<“\\nThe incentive is ” << incentive;
\n}<\/p>\n
\nA C++ program code is given below to find the value of X using the expression
\n\\(x=\\frac{a^{2}+b^{2}}{2 a}\\)
\nwhere a and b are variables
\n#include
\nusing namespace std;
\nintmain( )
\n{
\nint a;b;
\nfloat x \u2019
\ncout<<“Enter the values of a and b; cin>a>b;
\nx=a*a+b*b\/2*a;
\ncout>>x;
\n}<\/p>\n
\ni) a=4 b=8
\nii) a=0 b=2
\nAnswer:
\nThis program contains sortie errors and the correct program is as follows.
\n#include
\nusing namespace std;
\nint main( )
\n{
\nint a,b; . . .
\nfloat x;
\ncout<<“Enter the values of a and b”; cin>>a>>b;
\nx=(a*a+b*b)\/(2*a);
\ncout<<x;
\n}
\nThe output is as follows
\ni) a=4 and b= 8 then the output is 10
\na=0 and b= 2 then the output is an error divide by zero error(run time error)<\/p>\n
\nA list of data items are given below
\n45,8.432, M, 0.124,8 , 0, 8.1X 1031, 1010, a, 0.00025, 9.2 X1012O, 0471 ,-846, 342.123E03
\na) Categorise the given data under proper headings of fundamental data types in C++
\nb) Explain the specific features of each data type. Also mention any other fundamental data type for which sample data is not given.
\nAnswer:
\n
\nb) i) int data type:-<\/strong> It is used to store whole numbers without fractional (decimal point) part. It can be either negative or positive. It consumes 4 bytes (32 bits) of memory.i.e.- 232<\/sup> . numbers. That is 231<\/sup> negative numbers and 231<\/sup> positive numbers (0 is considered as +ve ) So a total of 232<\/sup> numbers. We can store a number in between -231<\/sup> to + 231<\/sup>-1.<\/p>\n
\nWrite valid reasons after reading the following statements in C++ arid comment on their correctness by give reasons.
\ni) char num=66;
\nchar num =’B’;
\nii) 35 and 35L are different
\niii) The number 14,016 and OxE are one and the same
\niv) Char data type is often said to be an integer type.
\nv) To store the value 4.15 float data type is preferred over double
\nAnswer:
\ni) The ASCII number of B is 66. So it is equivalent.
\nii) 35 is of integer type but 35L is Long
\niii) The decimal number 14 is represented in octal is 016 and in hexadecimal is OxE.
\niv) Internally char data type stores ASCII numbers.
\nv) To store the value 4.15 float data type is better because float requires only 4 bytes while double needs 8 bytes hence we can save the memory.<\/p>\n
\nSuggest most suitable derived data types in C++ for storing the following data items or statements :
\nrived data type
\ni) Age of 50 students in a class
\nii) Address of a memory variable’
\niii) A set of instructions to find out the factorial of a number
\niv) An alternate name of a previously defined variable
\nv) Price of 100 products in a consumer store
\nvi) Name of a student
\nAnswer:
\ni) Integer array of size 50
\nii) Pointer variable
\niii) Function
\niv) Reference
\nv) Float array of size 100
\nvi) Character array<\/p>\n
\nConsidering the following C++ statements.
\nFill up the blanks<\/strong>
\ni) If p=5 and q=3 then q%p is
\nii) If E1 is true and E2 is False then E1 && E2 will be
\niii) If k=8, ++k <= 8 will be = ______.
\niv) If x=2 then (10* ++x) % 7 will be ______.
\nv) If t=8 and m=(n=3,t-n), the value of m will be ______.
\nvi) If i=12 the value i after execution of the expression i+=i– + –i will be _____.
\nAnswer:
\ni) 3
\nii) False
\niii) False(++k makes k=9. So 9<=8 is false) ‘
\niv) 2(++x becomes 3 ,so 10 * 3 =30%7 =2)
\nv) 5( here m=(n=3,8-3)=(n=3,5), so m=5, The maximum value will take)
\nvi) Herei=12
\ni + = i– + -i
\nhere post decrement has more priority than pre decrement. .
\nSo i– will be evaluated first. Here first uses the value then change so it uses the value 12 and i becomes 11
\ni + =12 + –i
\nnow i =11.
\nHere the value of i will be changed and used so i~ becomes 10.
\ni — = 12 + 10
\n= 22
\nSo i =22+10
\ni =32
\nSo the result is 32.<\/p>\n
\nThe Maths teacher gives the following problem to Riya and Raju.
\nX=5 + 3*6. Riya got x=48 and Raju got x=23. Who is right and why it is happened ? Write down the operator precedence in detail?
\nAnswer:
\nHere the answer is x=23. It is because of precedence of operators. The order of precedence of operators are given below.
\n
\nHere multiplication has more priority than addition.<\/p>\n
\nb) Explain the data types in C++
\nAnswer:
\nFundamental data types:<\/strong> It is also called built in data type. They are int, char, float, double and void
\ni) int data type:<\/strong> It is-used to store whole numbers without fractional (decimal point) part. It can be either negative or positive. It consumes 4 bytes (32 bits) of memory.i.e. 232<\/sup> numbers. That is 231<\/sup> negative numbers and 231<\/sup> positive numbers (0 is considered as +ve) So a total of 2 numbers. We can store a number in between -231<\/sup> to + 231<\/sup>1.<\/p>\n
\neg. \u2018A\u2019,’?\u2019, \u20189\u2019 It consumes one byte(8 bits) of memory. If is internally treated as integers, i.e. 28<\/sup> = 256 characters. Each character is having a ASCII code, \u2018a\u2019 is having ASCII code 97 and zero is having ASCII code,48.<\/p>\n
\nUser defined Data types : C++ allows programmers to define their own data type. They are Structure(struct), enumeration (enum), union, class, etc.
\nDerived data types : The data types derived from fundamental data types are called Derived data types. They are Arrays, pointers, functions, etc<\/p>\n
\nPredict the output of the following C++ statements:
\nint a = -5, b = 3, c = 4;
\nC+ = a+++ — b; .
\ncout<<a<<b<<c;
\nAnswer:
\na = -4, b = 2 and c = 1<\/p>\n
\nMatch the following
\n
\nAnswer:
\n1. (vi) *
\n2. (v) &&
\n3. (ii) >=
\n4. (iii) >>
\n5. (i) ++
\n6. (iv) ?:<\/p>\n
\nWrite any five unary operators of C++. Why are they called so?
\nAnswer:
\nA unary operator is an operator that need only one operand to perform the operation. The five unary operators of C++ are given below.
\nUnary +, Unary -, ++, – – and ! (not)<\/p>\n
\nWrite C++ examples for the following:
\na) Declaration statement
\nb) Assignment statement
\nc) Type casting
\nAnswer:
\na) int age;
\nb) age= 16;
\nc) avg=(float)a+b+c\/3;<\/p>\nPlus One Computer Application Data Types and Operators 5 Marks Questions and Answers<\/h3>\n
\n
\nConsider the above data, we know that there are different types of data are used in the computer. Explain different data types used in C++.
\nAnswer:
\ni) int data type:<\/strong>\u00a0It is used to store whole numbers without fractional (decimal point) part. It can be either negative or positive. It consumes 4 bytes (32 bits) of memory.i.e. 232 numbers. That is 231 negative numbers and 231 positive numbers (0 is considered as +ve) So a total of 232 numbers. We can store a number in between -231 to + 2311.<\/p>\n
\neg; \u2019A\u2019.,’?’, ‘9’,…. It consumes one byte( 8 bits) of memory. It is internally treated as integers, i.e. 28 = 256 characters. Each character is having a ASCII code, ‘a’ is having ASCII code 97 and zero is having ASCII code 48.<\/p>\n
\nEg. 67.89,89.9 E-15.<\/p>\n
\nDefine an operator and explain operator in detail.
\nAnswer:
\nAn operator is a symbol that performs an operation. The data on which operations are carried out are called operands. Following are the operators
\n1) lnput(>>) and output(<<) operators<\/strong> are used to perform input and output operation. Eg. cin>>n;
\ncout<<n;
\n2) Arithmetic operators:<\/strong> It is a binary operator. It is used to perform addition(+), subtractionf-), division (\/), multiplication (*) and modulus (%- gives the remainder) operations.
\nEg. If x=10 and y=3 then
\n<\/p>\n
\n3) Relational operator:<\/strong> It is also a binary opera- tor. It is used to perform comparison or relational operation between two values and it gives either true(1) px false(O). The operators are <,<=,>,>=,== (equallty)and !=(not equal to)
\nEg. If x-10 and y=3 then
\n
\n4) Logical operators :<\/strong> Here AND(&&), OR(||) are binary operators and NOT(!) is a unary operator. It is used to combine relational operation? and it gives either true(1) or false(O).
\nIf x=True and y=False then
\n
\nBoth operands must be true to get a true value in the case of AND(&&) operation If x=True and y=False then
\n
\nEither one of the operands must be true to get a true value in the case of OR(||) operation If x=True and y=False then
\n
\n5) Conditional operator:<\/strong> It is a ternary operator hence it needs three operands. The operator is?:. Syntax: expression ? value if true : value if false. First evaluates the expression if it is true the second part wilt be executed otherwise the third part will be executed.
\nEg. If x=10 and y=3 then x>y ? cout< Here the output is 10.<\/p>\n
\nEg. sizeof(int) gives 2.<\/p>\n
\nb) Decrement operator (–) :<\/strong> It is used to decrement the value of a variable by one i.e., x-is equivalent to x = x-1.<\/p>\nPlus One Computer Application Chapter Wise Questions and Answers<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"