0% found this document useful (0 votes)
7 views15 pages

FPPS FinalExam

The document outlines the structure and requirements for a final exam in a programming course, covering topics such as variable swapping, random string printing, object-oriented programming, dynamic memory allocation, and creating an openFrameworks application. Each section includes code snippets that need to be modified or completed, along with expected outputs. Students are instructed to submit their completed code along with their name and student ID.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

FPPS FinalExam

The document outlines the structure and requirements for a final exam in a programming course, covering topics such as variable swapping, random string printing, object-oriented programming, dynamic memory allocation, and creating an openFrameworks application. Each section includes code snippets that need to be modified or completed, along with expected outputs. Students are instructed to submit their completed code along with their name and student ID.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2025_FPPS_Final Exam

Duration: 60 minutes

.
, , (ˮResult: “)

A4 ,
.

Please read and follow the instructions carefully.

The final output format must match the example exactly,


excluding only the values.
For example, line breaks, spacing, and the text that appears before the result(ˮResult: “) must be
exactly the same.

You may refer to your A4 summary sheet during the exam.


Please submit it with your name and student ID when you finish the
exam.

2025_FPPS_Final Exam 1
1. Swap Variable Values (3 pts)

#include <iostream>

void swap(int *a, int *b)


{

int main() {
int a  5;
int b  10;

std::cout << "Before: a = " << a << ", b = " << b << std::endl;
swap(&a, &b);
std::cout << "Before: a = " << a << ", b = " << b << std::endl;

return 0;
}

a b , b a ,
.

- , .

* .

Modify the code so that


the values of `a` and `b` are swapped using the `swap()` function.
Your program must produce the output exactly as shown below.

- the variablesʼ values must actually be swapped (not just printed differently).

* Submit the full code including the part given above.

Expected Output

Before: a  5, b  10
After: a  10, b  5

Untitled 1
2. Print Random Strings (3 pts)

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;

string words[] = {
"cat", "dog", "apple", "banana", "jump", "run", "code", "hello", "world"
};

int len  9;

int main()
{

words 10 .
- while, do-while, for .
- .
* .

Modify the code above to print randomly selected 10 strings from the words array.
 You must use one of the loops: while, do-while, or for.
 The result should be different each time the program is run.
* Submit the complete code including the provided part above.

Sample Output

world
hello
world
cat
banana
run
cat
banana
code
apple

Untitled 1
3. OOP - Encapsulation, Inheritance (4 pts)

#include <iostream>

using namespace std;

class Animal {

[____1____]:
string name;
int age;

public:
Animal() {}

Animal(string n, int a) {
name = n;
age = a;
}

void introduce() {
cout << "I am " << name << ", "
<< age << " years old." << endl;
}
};

class Person : public [____2____] {

public:
[____3____]() {}

[____3____](string n, int a) {
name = n;
age = a;
}

void talk() {
cout << name << " Yeah!" << endl;
}
};

class Cat : public [____2____] {

Untitled 1
public:
Cat() {}

Cat(string n, int a) {
name = n;
age = a;
}

void meow() {
cout << name << " Meow!" << endl;
}
};

int main()
{
Person p1  ____3____]("John", 121;
Cat c1  Cat("Mimi", 12;

[Link]();
p1.[____4____];

[Link]();
[Link]();

return 0;
}

Animal (Person, Cat)


.

This code defines two sub classes Person, Cat) that inherit from the Animal class,
and uses objects from these classes.

Fill in the blanks to make the program work as intended.

Expected Output

I am John, 121 years old.


John: Yeah!

Untitled 2
I am Mimi, 12 years old.
Mimi: Meow!

Answer sheet format:

1. abcde 🡒 [__1__] (your answer for blank [__1__])


2. abcde!
3. aabcde!!
.
.

Untitled 3
4. Dynamic Memory Allocation (4pts)
ofApp.h

#pragma once

#include "ofMain.h"

class Square {

private:
float posX, posY, width, height;

public:
Square(float x, float y, float w, float h)
{
posX  x;
posY  y;
width = w;
height = h;
}

Square() {};

void show()
{
ofSetColor(0, 20, 100, 100;
ofDrawRectangle(posX, posY, width, height);
}

};

class ofApp : public ofBaseApp{

public:
void setup() override;
void update() override;
void draw() override;
void exit() override;

int width, height;


int numRect;

Square [______1______];
};

Untitled 1
[Link]

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup()
{

ofSetFrameRate(30);

width = ofGetWidth();
height = ofGetHeight();

std::cout << "How many squares? ";


std::cin >> numRect;
squares = [______2______];

for (int i  0; i < numRect; i++)


{
int r = ofRandom(10, 50;
squares[i]  Square(
width * ofRandom(0, 1.0,
height * ofRandom(0, 1.0,
r,
r
);
}
}

//--------------------------------------------------------------
void ofApp::update()
{

//--------------------------------------------------------------
void ofApp::draw()
{

ofBackground(255);

for (int i  0; i < numRect; i++)


{
[______3______];
}
}

//--------------------------------------------------------------

Untitled 2
void ofApp::exit()
{
[______4______];
}

Square ,
openframeworks .

The code above is an openFrameworks program that


creates an array of Square objects using dynamic memory allocation and
visualizes them on the screen.

Fill in the blanks to make the program work as intended.

Expected Output The user input: 100

:
Answer sheet format:

Untitled 3
1. abcde 🡒 [__1__] (your answer for blank [__1__])
2. abcde!
3. aabcde!!
.
.

Untitled 4
5. Print self-introductions and the average age (6 pts)

#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

class Person {

private:
string name;
string place;
int age;

public:
Person() {};
Person(string nm, string pl, int ag  11
{
name = nm;
place = pl;
age = ag;
}

// Getter
string getName()
{
return name;
}

int getAge()
{
return age;
}

void introduce()
{
cout <<
"Hello! I'm " << name <<
" and I'm in " << place <<
", and I'm " << age << " years old." <<
endl;
}
};

Untitled 1
int main()
{
Person p1  Person("John", "Daejeon", 43;
Person p2  Person("Helen", "Jeju", 29;
Person p3  Person("Mark", "Seoul", 82;
Person p4  Person("Lee", "GeumSan");

vector<Person> persons;
persons.push_back(p1);
persons.push_back(p2);
persons.push_back(p3);
persons.push_back(p4);

float avg, sum  0;

cout << "The average age is: " << avg << endl;

return 0;
}

05_answer.cpp
.
- OOP .
- 3 .

* .

Modify 05_answer.cpp file to print self-introductions and the average age.


 Follow the principles of OOP encapsulation.
 The result must be displayed with 3 decimal place.

* Submit the complete code including the provided part above.

Expected Output

Hello! I'm John and I'm in Daejeon, and I'm 43 years old.
Hello! I'm Helen and I'm in Jeju, and I'm 29 years old.
Hello! I'm Mark and I'm in Seoul, and I'm 82 years old.
Hello! I'm Lee and I'm in GeumSan, and I'm 11 years old.
The average age is: 41.250

Untitled 2
oF (oF Project)
6. Create an oF App (10 pts)

oF .
1. oF .
2. posX, posY, radius, col Circle .
3. std::vector .
4. , ,
20 ~ 60 .

( )
5. .( 2 )
6. , .( 1~2 )

Refer to the attached video and implement an oF project that


satisfies the following conditions:
1. Create a new openFrameworks project.
2. Define a Circle class with the following member variables:
posX, posY, radius, and col (for color).
3. Use std::vector to manage the objects.
4. When the mouse is clicked on the canvas,
a new circle should be created at that position with:
 A random radius between 20 and 60
 A random color

Optional below)
5. When the space bar is pressed,
the color of all circles should change to random values. Additional 2 pts)
6. You are welcome to demonstrate your creativity by adding features:
such as adding movement, implementing interaction and so on.
Additional 1  2 pts)

oF

oF method reference

// ofColor RGB .
// ofColor can store RGB values for a color.

Untitled 1
ofColor col = ofColor(value_red, value_green, value_blue);
col.r // col red , The red value of col
col.g // col green , The green value of col
col.b // col blue , The blue value of col

// .
// Set the background color.
ofBackground(value_red, value_green, value_blue, value_alpha);

// 0 MAX .
// Returns a random value between 0 and MAX (exclusive)
ofRandom(MAX);

// MIN MAX .
// Returns a random value between MIN and MAX (exclusive)
ofRandom(MIN, MAX;

// true .
// Returns true if the mouse button is currently pressed
ofGetMousePressed();

// x .
// Returns the current x position of the mouse
ofGetMouseX;

// y .
// Returns the current y position of the mouse
ofGetMouseY;

// ( ).
// Sets the resolution of circles (number of segments used to draw the circle)
ofSetCircleResolution(32);

// .
// Sets the frame rate (number of frames per second)
ofSetFrameRate(30);

Untitled 2
Submission Instructions

[Link], ofApp.h, [Link] src .


Only submit the `src` folder that contains [Link], ofApp.h, and [Link].

Untitled 3

You might also like