Question

a) Name 5 different “data types” used in C++ programming. b) Give an example of the...

a) Name 5 different “data types” used in C++ programming.

b) Give an example of the kind of data that would be kept in each of the types listed in question (a).

c) What does it mean to pass a variable by “reference” rather than by “value?”

d) When would the above be useful to do?

e) What does the following code do?

int val;

cout << “Enter a value for processing: ”;

cin >> val;

cout << val < 0 ? -val : val;

f) What is the second line of the above code segment used for?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer a.) 5 different data types used in c++ are :

Integer, Floating point, Boolean, Character, Void or valueless (int, float, bool, char, void)

Answer b.)

int - any integer like 0, 1, -10, 298

float- any number having decimal point as well like 2.00 , 289.003

bool- “true” or “false”

char- any character value example alphabets ‘a’ , ‘m’, ‘z’... any special symbol like ‘&’ , ‘@‘

void- means without a value, used for functions which do not return anything.

Answer c.) Let’s understand both by examples

Say I have a function :

void incByOne (int a){

a=a+1;

}

int main(){

int x=2;

incByOne(x);

cout<<x; //will print 2 since value of x is not changed by function incByOne as the value was passed to it as ‘pass by value’

return 0;

}

now if we have same function but the arguments are passed as a reference like below

void incByOne (int &a){

a=a+1;

}

int main(){

int x=2;

incByOne(x);

cout<<x; //will print 3 now since value of x is changed by function incByOne as the value was passed to it as ‘pass by reference’

}

Answer d.) When we don’t want the function to make its own argument copies and act on them , and instead we want to use our own passed arguments inside the function doing all the calculations on them directly we can use pass by reference .

Answer e.) The program asks the user to enter an integer value

If the entered value is less than zero, it prints the same negative number as in number with a minus sign

if the entered value is greater than or equal to zero, the same number is printed on console .

Answer f.) the second line prompts on the console “Enter a value for processing” ,

prompting the user to enter a value on the input device

Add a comment
Know the answer?
Add Answer to:
a) Name 5 different “data types” used in C++ programming. b) Give an example of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HALIX PROGRAMMING C++ 1. Write Halix machine code to read and add 5 values. Test cases:...

    HALIX PROGRAMMING C++ 1. Write Halix machine code to read and add 5 values. Test cases: 1 2 3 4 5 ==>15 -1 -2 -3 -4 23 ==> 13 0 0 0 0 0 ==> 0 2. Write Halix machine code to read a value: Double it if the nu halve it when it's odd. Test cases: 14 ==> 28 0 ==>0 25==>12 -2==>-4 -7==>-3 3. Write a program that reads ans echoes (display what was just values that are...

  • 6. (Short answer) The C++ code below is very close to working, but, as written, won't...

    6. (Short answer) The C++ code below is very close to working, but, as written, won't compile. When trying to compile, the compiler generates a number of errors similar to "cout' was not declared in this scope." Respond to the prompts below about the code.(20 points, 5 points each) #include <iostream> void FindMax(int a, int b, int& max) { if (a > b) max = a; else { max = b; } int main() { int num1 = 0; int...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • IN C-PROGRAMMING: What is Structured Programming; what is machine and assembly coding; what is pseudo coding?...

    IN C-PROGRAMMING: What is Structured Programming; what is machine and assembly coding; what is pseudo coding? What do the following do:   compiler, preprocessor, return 0, { }? Describe data types and what distinguishes each;  how would one combine data types? Explain functions and what are they for? Explain:  scanf (gets, fgets, getchar, fgetchar), printf( puts, fputs, putchar, fpetchar) What do the following mean:   strlen, strcmp, strcat, strcpy? What does fopen and fclose mean? Explain the difference between stdin and file. What if your file...

  • Part 5: C++ Programming (25/100) 13) (5 marks) Explain the difference between a call by value...

    Part 5: C++ Programming (25/100) 13) (5 marks) Explain the difference between a call by value and a call by reference. 14) (5 marks) What value of y will be displayed when the following ++ program is run: tinclude <iostream int main) double x 3.0, y: y1/3 x16.0) std::cout <<y<"n" return (0): Show the details step by step as how the computer would perform the calculation and justify your resuits. Also, what will the data type of y be? For...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • C++ 1. How do functions facilitate modular programming? 2. What does a function prototype do? 3....

    C++ 1. How do functions facilitate modular programming? 2. What does a function prototype do? 3. What does "calling" a function mean? 4. If you have two or more functions with the same name, what has to be true of them? 5. How would you explain the difference between pass-by-value and pass-by-reference?

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • How to call a function in another function?C++ Project assistance. In the Project I am attempting...

    How to call a function in another function?C++ Project assistance. In the Project I am attempting to pass getOutcome into runGame to attempt to figure out who would win. Upon trying I get an error that getOutcome isn't in scop of runGame. The & symbols were my last attempt at trying to pass it, I do see it is wrong, and any help that can help me with just that is very appreciated. #include <iostream> #include <fstream> #include <string> #include...

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT