0% found this document useful (0 votes)
21 views

Final Examination - Computer Fundamentals & Programming (Simara, Danilo III B.)

Computer Fundamentals & Programming

Uploaded by

Dennis Simara
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Final Examination - Computer Fundamentals & Programming (Simara, Danilo III B.)

Computer Fundamentals & Programming

Uploaded by

Dennis Simara
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FINAL EXAMINATION

COMPUTER FUNDAMENTALS AND PROGRAMMING

Name: Danilo B. Simara III


Course, Year, & Section: BSCE 1A
Instructor: Mrs. Joanna Estallo

Test II: Write a program in C++. Declare its codes / syntax.

1. What is a correct syntax to output “Hello World” in C++?


#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
}

2. How do you insert comments in C++ code?


// This is a comment used for Single-line Comments

/* This is a comment used for Multi-line Comments, wherein is commonly used for
longer comments in a code*/

1
3. How do you create a variable with the floating number 2.8?
The variable will be double myFloatNum = 2.8 /*Floating point number (with
decimals)*/

Example:
#include <iostream>
using namespace std;

int main() {
double myFloatNum = 2.8;
cout << myFloatNum;
}

4. To declare an array in C++, define the variable type with:


To declare an array, define the variable type, specify the name of the
array followed by square brackets and specify the number of elements.

Example:
#include <iostream>
#include <string>
using namespace std;

int main() {
//I will use clothing brands as a variable
string brands [3] = {"Bench", "Penshoppe", "Fubu"} ; //The variable and values on it
cout << brands[0];
return 0;
}

2
5. Which keyword is used to create a class in C++?

The class keyword is used to create a class called MyClass.

Example:
#include <iostream>
using namespace std;

class MyClass { // The class


public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};

int main() {
MyClass myObj; // Create an object of MyClass

// Access attributes and set values


myObj.myNum = 8;
myObj.myString = "Class in C++ by Danilo Simara III";

// Print attribute values


cout << myObj.myNum << "\n";
cout << myObj.myString;
return 0;
}

You might also like