100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Tentamen (uitwerkingen)

COSC1436 Exam Questions and Answers Latest Update Graded A+

Beoordeling
-
Verkocht
-
Pagina's
46
Cijfer
A+
Geüpload op
23-10-2024
Geschreven in
2024/2025

COSC1436 Exam Questions and Answers Latest Update Graded A+ What's the difference between initializing a variable and assigning a value to a variable? - Answers Assigning is storing a value into the variable's memory location. Once you assign a value, you can reassign another value at any time. Initializing is simply assigning a value to a variable for the first time. Declare an integer variable called ageOfStudent and initialize it to 16. - Answers int ageOfStudent = 16; Declare a doublevariable called tipRateandinitializeit to .20. - Answers double tipRate = .20; Declare twostringvariables called firstName, and lastName, but do not initialize them to anything - Answers string firstName, lastName; Given an integer variable called ageOfStudent (assume it is already set), write a statement that will display the value of ageOfStudent. - Answers cout << ageOfStudent; Given a double variable called tipRate (assume it is already set to .20), write a statement that will display the value of tipRate with two decimal places. - Answers cout << fixed << setprecision(2) << tipRate; Given two string variables called firstName and lastName (assume they are both already initialized), write a statement that will display the values of firstName followed by a space, followed by the lastName - Answers cout << firstName << " " << lastName << endl; Given two string variables called firstName and lastName (assume they are both already initialized), write a statement that will display the values of lastName in a field of 20 spaces (rightjustified), followed by the value of firstName in a field of 20 spaces, also right-justified). - Answers cout << setw(20) << lastName << setw(20) << firstName; Assume that m is an int variable that has already been given a value. Write a statement that prints out the value of m in a field of 10 positions. - Answers cout << setw(10) << m; Given two integer variables distance and speed, write an expression that divides distance by speed using floating point arithmetic. - Answers (double) distance/speed Assume that students is an integer variable containing the number of students in a school, and that teachers is an integer variable containing the number of teachers in the same school. Write a statement that will print out the average number of students per teacher. Keep in mind that we want the answer to have a decimal number. Hint: You will need to use type-casting. You may use the long or short version of type casting - Answers cout << (double) students/teachers; . Given an int variable datum that has already been declared, write a statement that reads an integer value from standard input into this variable. - Answers cin >> datum; Given a string variable firstName that has already been declared, write a statement that reads a name from standard input into this variable. - Answers cin >> firstName n. Given a string variable firstAndLastName that has already been declared, write a statement that reads an entire name (first and last name) from standard input into this variable. For example, the user might enter "J. K. Rowling" or "Robyn Rihanna Fenty", or "Madonna", etc.... - Answers getline(cin, firstAndLastName); Write an if statement to determine if the int variable age is within the range of 0 through 17 (including both those ages). Simply write the: if (condition) - Answers if (age >= 0 && age <= 17) . Write an if statement to determine if the int variable age is less than 0 or greater than 17. Simply write the: if (condition) - Answers if (age < 0 | | age > 17) . Assume the following: if (funny == 5) cout << "So funny!" << endl; else if (funny == 10)

Meer zien Lees minder
Instelling
COSC1436
Vak
COSC1436











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
COSC1436
Vak
COSC1436

Documentinformatie

Geüpload op
23 oktober 2024
Aantal pagina's
46
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

Voorbeeld van de inhoud

COSC1436 Exam Questions and Answers Latest Update Graded A+

What's the difference between initializing a variable and assigning a value to a variable? - Answers
Assigning is storing a value into the variable's memory location. Once you assign a value, you can
reassign another value at any time.



Initializing is simply assigning a value to a variable for the first time.

Declare an integer variable called ageOfStudent and initialize it to 16. - Answers int ageOfStudent = 16;

Declare a doublevariable called tipRateandinitializeit to .20. - Answers double tipRate = .20;

Declare twostringvariables called firstName, and lastName, but do not initialize them to anything -
Answers string firstName, lastName;

Given an integer variable called ageOfStudent (assume it is already set), write a statement that will

display the value of ageOfStudent. - Answers cout << ageOfStudent;

Given a double variable called tipRate (assume it is already set to .20), write a statement that will

display the value of tipRate with two decimal places. - Answers cout << fixed << setprecision(2) <<
tipRate;

Given two string variables called firstName and lastName (assume they are both already

initialized), write a statement that will display the values of firstName followed by a space, followed

by the lastName - Answers cout << firstName << " " << lastName << endl;

Given two string variables called firstName and lastName (assume they are both already

initialized), write a statement that will display the values of lastName in a field of 20 spaces
(rightjustified), followed by the value of firstName in a field of 20 spaces, also right-justified). - Answers
cout << setw(20) << lastName << setw(20) << firstName;

Assume that m is an int variable that has already been given a value. Write a statement that prints

out the value of m in a field of 10 positions. - Answers cout << setw(10) << m;

Given two integer variables distance and speed, write an expression that

divides distance by speed using floating point arithmetic. - Answers (double) distance/speed

Assume that students is an integer variable containing the number of students in a school, and

that teachers is an integer variable containing the number of teachers in the same school. Write a

,statement that will print out the average number of students per teacher.

Keep in mind that we want the answer to have a decimal number.

Hint: You will need to use type-casting. You may use the long or short version of type casting - Answers
cout << (double) students/teachers;

. Given an int variable datum that has already been declared, write a statement that reads an integer

value from standard input into this variable. - Answers cin >> datum;

Given a string variable firstName that has already been declared, write a statement that reads a

name from standard input into this variable. - Answers cin >> firstName

n. Given a string variable firstAndLastName that has already been declared, write a statement that

reads an entire name (first and last name) from standard input into this variable. For example, the

user might enter "J. K. Rowling" or "Robyn Rihanna Fenty", or "Madonna", etc.... - Answers getline(cin,
firstAndLastName);

Write an if statement to determine if the int variable age is within the range of 0 through 17

(including both those ages). Simply write the: if (condition) - Answers if (age >= 0 && age <= 17)

. Write an if statement to determine if the int variable age is less than 0 or greater than 17. Simply

write the: if (condition) - Answers if (age < 0 | | age > 17)

. Assume the following:

if (funny == 5)

cout << "So funny!" << endl;

else if (funny == 10)

cout << "Seriously funny!" << endl;

else

{

cout << "ERROR!" << endl;

cout << "Incorrect choice!" << endl;

}

,Rewrite the above if statement as a switch - Answers switch (funny) {



case 5:

cout << "So funny!" << endl;

break



case 10:

cout << "Seriously funny!"<<endl;

break



default:

cout << " ERROR!" << endl;

cout << "Incorrent choice!" << endl;

}

Given the variable temperature write an expression that evaluates to true if and only if the

temperature is equal to 32. This is just the expression (e.g., A>B, A<=B, etc...). Do not use parenthesis or
an equal sign. - Answers temperature == 32

. Given the variables temperature and humidity, write an expression that evaluates to true if and

only if the temperature is greater than 90 and the humidity is less than 10.

Remember, this is just an expression (e.g., A>B, A==B, etc...). Do not use parenthesis or an equal

sign. - Answers temperature > 90 && humidity < 10

Assume the following:

int age;

int baby=child=teen=0;

cout << "Enter age of child: ";

cin >> age;

, Write the entire if/else-if/else statement that will:

• Increment by 1 the baby variable if the ageis between 0 and 2 (including both those values)

• Increment by 1 the child variable if the ageis between 3 and 12 (including both those values)

• Increment by 1 the teen variable if the age is between 13 and 17 (including both those values)

• Display an error message if the the age is less than 0 or greater than or equal to 18 - Answers if (age >=
0 && age <= 2)

baby++;



else if (age >= 3 && age <= 12)

child++;



else if (age >= 13 && age <= 17)

teen++;



else

cout << "ERROR";

. The formula to compute the circumference of a circle is (where r is the radius of the circle and =

3.14159):

circumference = 2r

Write C++ statements to do the following:

i. Declare a constant PI and initialize it to 3.14159



ii. Declare a variable radius of type double



iii. Declare a variable circ of type double

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
TutorJosh Chamberlain College Of Nursing
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
342
Lid sinds
1 jaar
Aantal volgers
16
Documenten
28567
Laatst verkocht
1 dag geleden
Tutor Joshua

Here You will find all Documents and Package Deals Offered By Tutor Joshua.

3.6

53 beoordelingen

5
18
4
14
3
12
2
0
1
9

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen