Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. What are the differences between procedural programming and object-oriented programming?
There are primarily two methods of programming in use today: procedural and object oriented. The
earliest programming languages were procedural, meaning a program was made of one or more
procedures. A procedure is a set of programming statements that, together, perform a specific task. The
statements might gather input from the user, manipulate data stored in the computer’s memory, and
perform calculations or any other operation necessary to complete the procedure’s task.
Procedures typically operate on data items that are separate from the procedures. In a procedural
program, the data items are commonly passed from one procedure to another. As you might imagine, the
focus of procedural programming is on the creation of procedures that operate on the program’s data.
The separation of data and the code that operates on the data often leads to problems, however. For
example, the data is stored in a particular format, which consists of variables and more complex
structures that are created from variables. The procedures that operate on the data must be designed with
that format in mind. But what happens if the format of the data is altered? Quite often, a program’s
specifications change, resulting in a redesigned data format. When the structure of the data changes, the
code that operates on the data must also be changed to accept the new format. This results in added work
for programmers and a greater opportunity for bugs to appear in the code.
This has helped influence the shift from procedural programming to object-oriented programming
(OOP). Whereas procedural programming is centered on creating procedures, object-oriented
programming is centered on creating objects. An object is a software entity that contains data and
procedures. The data contained in an object is known as the object’s attributes. The procedures, or
behaviors, that an object performs are known as the object’s methods. The object is, conceptually, a self-
contained unit consisting of data (attributes) and procedures (methods).
OOP addresses the problem of code/data separation through encapsulation and data hiding.
Encapsulation refers to the combining of data and code into a single object. Data hiding refers to an
object’s ability to hide its data from code that is outside the object. Only the object’s methods may then
directly access and make changes to the object’s data. An object typically hides its data, but allows
outside code to access the methods that operate on the data.
2. Find an example in the real world where the Object Technology is applied with success.
Hypermedia, on the other hand, is a superset of hypertext. Documents having hypermedia, not only
contain links to other pieces of text and information, but also to numerous other forms of media,
ranging from images to sound.
Email
Word processing
Web calendars
Desktop publishing
#include <iostream>
#include <cctype>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
struct PlayerInfo
{
string name;
int color;
int point;
};
void showMenu();
int getChoice();
void generateBoard(int [][COL], string [][COL]);
void showBoard(int [][COL], string [][COL]);
bool isDuplicated(int [][COL], int, int, int);
void changeBoard(int [][COL], string [][COL]);
void playBoard(PlayerInfo [], int [][COL], string [][COL]);
void showResult(PlayerInfo []);
int main()
{
int boardNum[ROW][COL];
string boardName[ROW][COL];
int choice;
PlayerInfo player[SIZE];
generateBoard(boardNum, boardName);
do
{
system("cls");
showMenu();
choice = getChoice();
if (choice != 5)
{
switch (choice)
{
case 1: showBoard(boardNum, boardName);
break;
case 2: changeBoard(boardNum, boardName);
break;
case 3: playBoard(player, boardNum, boardName);
break;
case 4: showResult(player);
}
}
} while (choice != 5);
return 0;
}
void showMenu()
{
cout << "\t---Chao mung toi gameshow Hanh Khach Cuoi Cung---\n\n";
cout << "1. Hien ra bang choi\n";
cout << "2. Thay doi vi tri mau\n";
cout << "3. Bat dau phan choi\n";
cout << "4. Ket qua\n";
cout << "5. Thoat chuong trinh\n\n";
}
int getChoice()
{
int choice;
return true;
}
LECTURE 2
The recipe produces 48 cookies with these amounts of the ingredients. Write a program
that asks the user how many cookies he or she wants to make, and then displays the number of cups of each
ingredient needed for the specified number of cookies.
import java.util.Scanner;
double sugar,
butter,
flour;
int cookie;
After the user has entered these items, the program should display the following story,
inserting the user’s input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of AGE,
NAME went to college at COLLEGE. NAME graduated and went to work as a
PROFESSION. Then, NAME adopted a(n) ANIMAL named PETNAME. They both lived
happily ever after!
import java.util.Scanner;
LECTURE 3
Andy
Charlie
Leslie
import java.util.Scanner;
public class Homework
{
public static void main(String[] args)
{
String name1,
name2,
name3;
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Write a program that asks the user to enter the number of packages purchased. The program should then
display the amount of the discount (if any) and the total amount of the
purchase after the discount.
import java.util.Scanner;
public class Homework
{
public static void main(String[] args)
{
final int RETAIL = 99;
double total;
int packages;
The shipping charges per 500 miles are not prorated. For example, if a 2-pound package is
shipped 550 miles, the charges would be $2.20. Write a program that asks the user to enter
the weight of a package and then displays the shipping charges.
import java.util.Scanner;
public class Homework
{
public static void main(String[] args)
{
final double RATE1 = 1.10;
final double RATE2 = 2.20;
final double RATE3 = 3.70;
final double RATE4 = 3.80;
double miles,
weights,
charges,
ratio;