PRINT "Farenheit", "Celcius"
PRINT
PRINT "Enter Degree F", F
PRINT F, (F-32) * 5/9
PRINT GO TO 3
/*
* C++ Program to Perform Fahrenheit to Celsius Conversion
*/
#include <iostream>
double fahrenheitToCelsius(double fahrenheit)
{
double celsius;
celsius = (fahrenheit - 32.0) * 5.0 / 9.0;
return celsius;
}
int main()
{
double fahrenheit;
std::cout << "Enter temperature in fahrenheit (in degrees) ";
std::cin >> fahrenheit;
std::cout << "Temperature in Celsius (in degrees) = "
<< fahrenheitToCelsius(fahrenheit) << std::endl;
}
int x = 10; // x has a value of 10
x = 62; // x is now 20
x = x + 1; // x is now 63
int x,y; // ตัวแปรชื่อ x และ y เก็บเลขจำนวนเต็ม
float salary; // ตัวแปร salary เก็บเลขมีทศนิยม
structure employee {
int identifier;
char name[30];
float salary;
};
'Pascal
program Shop;
uses
Crt;
var
choice: integer;
total: real;
procedure DisplayMenu;
begin
ClrScr;
writeln('Welcome to the Shop!');
writeln('1. Apple - $1.00');
writeln('2. Banana - $0.75');
writeln('3. Orange - $1.25');
writeln('4. Checkout');
writeln('5. Exit');
write('Enter your choice (1-5): ');
end;
procedure AddToCart(price: real);
begin
total := total + price;
writeln('Item added to cart. Current total: $', total:0:2);
readln;
end;
begin
total := 0;
repeat
DisplayMenu;
readln(choice);
case choice of
1: AddToCart(1.00);
2: AddToCart(0.75);
3: AddToCart(1.25);
4: begin
writeln('Your total is: $', total:0:2);
writeln('Thank you for shopping with us!');
readln;
halt;
end;
5: writeln('Thank you for visiting. Goodbye!');
else
writeln('Invalid choice. Please try again.');
readln;
end;
until choice = 5;
end.
ไม่จำเป็นต้องแสดงหรือโชว์ ทราบแต่ว่าภายใน class สามารถทำงานได้
// Base class
class Animal {
public:
void animalSound() {
cout << "The animal makes a sound \n";
}
};
// Derived class
class Pig : public Animal {
public:
void animalSound() {
cout << "The pig says: wee wee \n";
}
};
// Derived class
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow \n";
}
};
int main() {
Animal myAnimal;
Pig myPig;
Dog myDog;
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
return 0;
}
Aj. Krit Th.
https://www.kritth.com