Sabtu, 18 April 2026

Python XML 4

 



import tkinter as tk
from tkinter import ttk
import xml.etree.ElementTree as ET

# 1. Sample XML Data (could be loaded from a file)
xml_data = """<?xml version="1.0"?>
<library>
    <book id="1">
        <title>Python Basics</title>
        <author>John Doe</author>
        <year>2020</year>
    </book>
    <book id="2">
        <title>Tkinter Guide</title>
        <author>Jane Smith</author>
        <year>2022</year>
    </book>
</library>
"""

def load_xml_data(tree):
    # Parse XML
    root = ET.fromstring(xml_data)
    
    # Iterate over XML elements and insert into treeview
    for book in root.findall('book'):
        book_id = book.get('id')
        title = book.find('title').text
        author = book.find('author').text
        year = book.find('year').text
        tree.insert("", "end", values=(book_id, title, author, year))

# Create GUI
root = tk.Tk()
root.title("XML to Treeview")

# 2. Setup Treeview
columns = ("id", "title", "author", "year")
tree = ttk.Treeview(root, columns=columns, show="headings")

# Define Headings
tree.heading("id", text="ID")
tree.heading("title", text="Title")
tree.heading("author", text="Author")
tree.heading("year", text="Year")

# Define Columns
tree.column("id", width=50)
tree.column("title", width=200)
tree.column("author", width=150)
tree.column("year", width=50)

tree.pack(pady=20)

# Load data
load_xml_data(tree)

root.mainloop()


Python XML 3




import tkinter as tk

from tkinter import ttk, messagebox, filedialog

import xml.etree.ElementTree as ET

import os


def load_xml_data(file_path):

    """Load and parse XML file, returning headers and rows."""

    try:

        tree = ET.parse(file_path)

        root = tree.getroot()


        # Assume each child of root is a row, and its sub-elements are columns

        rows = []

        headers = set()


        for row_elem in root:

            row_data = {}

            for col_elem in row_elem:

                headers.add(col_elem.tag)

                row_data[col_elem.tag] = col_elem.text or ""

            rows.append(row_data)


        headers = sorted(headers)  # Keep consistent order

        return headers, rows


    except ET.ParseError:

        messagebox.showerror("XML Error", "Invalid XML format.")

        return [], []

    except FileNotFoundError:

        messagebox.showerror("File Error", "File not found.")

        return [], []

    except Exception as e:

        messagebox.showerror("Error", str(e))

        return [], []


def display_table(headers, rows):

    """Display data in a Tkinter Treeview table."""

    # Clear old table if exists

    for widget in table_frame.winfo_children():

        widget.destroy()


    if not headers or not rows:

        tk.Label(table_frame, text="No data to display").pack()

        return


    # Create Treeview

    tree = ttk.Treeview(table_frame, columns=headers, show="headings")

    tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)


    # Add column headings

    for header in headers:

        tree.heading(header, text=header)

        tree.column(header, width=120, anchor="center")


    # Insert rows

    for row in rows:

        tree.insert("", tk.END, values=[row.get(h, "") for h in headers])


    # Add scrollbar

    scrollbar = ttk.Scrollbar(table_frame, orient="vertical", command=tree.yview)

    tree.configure(yscroll=scrollbar.set)

    scrollbar.pack(side=tk.RIGHT, fill=tk.Y)


def open_file():

    """Open file dialog and load XML data."""

    file_path = filedialog.askopenfilename(

        title="Select XML File",

        filetypes=[("XML Files", "*.xml"), ("All Files", "*.*")]

    )

    if file_path:

        headers, rows = load_xml_data(file_path)

        display_table(headers, rows)


# --- Tkinter GUI Setup ---

root = tk.Tk()

root.title("XML Data Table Viewer")

root.geometry("700x400")


# Menu

menu_bar = tk.Menu(root)

file_menu = tk.Menu(menu_bar, tearoff=0)

file_menu.add_command(label="Open XML", command=open_file)

file_menu.add_separator()

file_menu.add_command(label="Exit", command=root.quit)

menu_bar.add_cascade(label="File", menu=file_menu)

root.config(menu=menu_bar)


# Table Frame

table_frame = tk.Frame(root)

table_frame.pack(fill=tk.BOTH, expand=True)


# Start GUI

root.mainloop()

 



Python XML 2

 




import tkinter as tk
from tkinter import ttk
import xml.etree.ElementTree as ET

# Fungsi untuk memuat dan mencari data dari XML
def search_data():
    query = search_entry.get().lower()
    
    # Hapus data lama di tabel sebelum menampilkan hasil baru
    for row in tree.get_children():
        tree.delete(row)
        
    try:
        # Load file XML (Ganti 'data.xml' dengan nama file Anda)
        tree_xml = ET.parse('data2.xml')
        root = tree_xml.getroot()
        
        for item in root.findall('item'):
            # Ambil data dari tag XML (sesuaikan nama tag dengan file Anda)
            name = item.find('name').text
            category = item.find('category').text
            price = item.find('price').text
            
            # Filter berdasarkan input pencarian
            if query in name.lower() or query in category.lower():
                tree.insert("", "end", values=(name, category, price))
                
    except FileNotFoundError:
        print("Error: File 'data.xml' tidak ditemukan.")

# --- Setup GUI ---
root = tk.Tk()
root.title("Pencarian Data XML")
root.geometry("600x400")

# 1. Kotak Input Pencarian
search_frame = tk.Frame(root)
search_frame.pack(pady=10)

tk.Label(search_frame, text="Cari:").pack(side=tk.LEFT, padx=5)
search_entry = tk.Entry(search_frame, width=30)
search_entry.pack(side=tk.LEFT, padx=5)

# Tombol Search
search_btn = tk.Button(search_frame, text="Cari", command=search_data)
search_btn.pack(side=tk.LEFT)

# 2. Tabel Data (Treeview)
columns = ("Name", "Category", "Price")
tree = ttk.Treeview(root, columns=columns, show="headings")

# Definisi Header Tabel
for col in columns:
    tree.heading(col, text=col)
    tree.column(col, width=150)

tree.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)

# Jalankan fungsi pencarian pertama kali untuk memuat semua data
search_data()

root.mainloop()
==============================
data2.xml
<?xml version="1.0"?>
<root>
    <item>
        <name>Laptop</name>
        <category>Electronics</category>
        <price>1200</price>
    </item>
    <item>
        <name>Mouse</name>
        <category>Electronics</category>
        <price>100</price>
    </item>
    <item>
        <name>Speaker</name>
        <category>Electronics</category>
        <price>120</price>
    </item>
     <item>
        <name>Flasdisk</name>
        <category>Electronics</category>
        <price>10</price>
    </item>
    <item>
        <name>Keyboard</name>
        <category>Electronics</category>
        <price>120</price>
    </item>

</root>



Python XML 1

 



import tkinter as tk

from tkinter import ttk, messagebox

import xml.etree.ElementTree as ET

import os


# ---------------------------

# Load XML Data Function

# ---------------------------

def load_xml_data(file_path):

    """Load and parse XML data into a list of dictionaries."""

    if not os.path.exists(file_path):

        messagebox.showerror("Error", f"File not found: {file_path}")

        return []


    try:

        tree = ET.parse(file_path)

        root = tree.getroot()


        data_list = []

        for item in root.findall("record"):

            record_data = {

                "ID": item.findtext("id", "").strip(),

                "Name": item.findtext("name", "").strip(),

                "Age": item.findtext("age", "").strip(),

                "City": item.findtext("city", "").strip()

            }

            data_list.append(record_data)

        return data_list

    except ET.ParseError as e:

        messagebox.showerror("XML Parse Error", str(e))

        return []


# ---------------------------

# Search Function

# ---------------------------

def search_data():

    """Filter table based on search query."""

    query = search_var.get().lower().strip()

    table.delete(*table.get_children())  # Clear table


    for row in xml_data:

        if query in row["Name"].lower() or query in row["City"].lower():

            table.insert("", tk.END, values=(row["ID"], row["Name"], row["Age"], row["City"]))


# ---------------------------

# Main Tkinter Window

# ---------------------------

root = tk.Tk()

root.title("XML Search & Display")

root.geometry("600x400")


# Search Input

search_var = tk.StringVar()

tk.Label(root, text="Search:").pack(pady=5)

search_entry = tk.Entry(root, textvariable=search_var, width=40)

search_entry.pack(pady=5)

tk.Button(root, text="Search", command=search_data).pack(pady=5)


# Table (Treeview)

columns = ("ID", "Name", "Age", "City")

table = ttk.Treeview(root, columns=columns, show="headings")

for col in columns:

    table.heading(col, text=col)

    table.column(col, width=100)

table.pack(fill=tk.BOTH, expand=True, pady=10)


# Load XML Data

xml_file = "data.xml"  # Change to your XML file path

xml_data = load_xml_data(xml_file)


# Display all data initially

for row in xml_data:

    table.insert("", tk.END, values=(row["ID"], row["Name"], row["Age"], row["City"]))


root.mainloop()



=========================


data.xml


<?xml version="1.0"?>

<records>

    <record>

        <id>1</id>

        <name>John Doe</name>

        <age>30</age>

        <city>New York</city>

    </record>

    <record>

        <id>2</id>

        <name>Jane Smith</name>

        <age>25</age>

        <city>Los Angeles</city>

    </record>

    <record>

        <id>3</id>

        <name>Michael Brown</name>

        <age>40</age>

        <city>Chicago</city>

    </record>

</records>

Python Menu 3

 




import tkinter as tk


class App:

    def __init__(self, root):

        self.root = root

        self.root.geometry("600x400")

        

        # Menu toggle button

        self.btn_toggle = tk.Button(root, text="☰ Menu", command=self.toggle_menu)

        self.btn_toggle.place(x=10, y=10)


        # Sliding frame

        self.menu_frame = tk.Frame(root, bg="#333333", width=0, height=400)

        self.menu_frame.pack_propagate(False) # Allows width to change

        

        # Menu Items

        self.menu_items = [f"Menu Item {i}" for i in range(1, 8)]

        for item in self.menu_items:

            tk.Button(self.menu_frame, text=item, bg="#333333", fg="white", 

                      font=("Arial", 12), relief="flat", anchor="w").pack(fill="x", pady=5, padx=10)


        self.menu_visible = False


    def toggle_menu(self):

        if not self.menu_visible:

            # Slide In

            for i in range(0, 201, 20): # Width 0 to 200

                self.menu_frame.place(x=0, y=50, width=i, height=350)

                self.root.update()

        else:

            # Slide Out

            for i in range(200, -1, -20): # Width 200 to 0

                self.menu_frame.place(x=0, y=50, width=i, height=350)

                self.root.update()

        self.menu_visible = not self.menu_visible


root = tk.Tk()

app = App(root)

root.mainloop()

Python Menu 2

 




import tkinter as tk


class SlidingMenuApp:

    def __init__(self, root):

        self.root = root

        self.root.title("Sliding Menu")

        self.root.geometry("400x600")


        # Menu configuration

        self.menu_width = 200

        self.menu_height = 400

        self.is_open = False

        

        # Calculate hidden starting position (below the window)

        self.hidden_y = 600

        self.visible_y = 200 # Height where it stops


        # --- Create Menu Frame ---

        self.menu_frame = tk.Frame(self.root, bg="#333333", width=self.menu_width, height=self.menu_height)

        self.menu_frame.place(x=-self.menu_width, y=self.hidden_y) # Initially hidden

        self.menu_frame.pack_propagate(False) # Maintain size


        # --- Menu Items ---

        menu_items = ["menuitem1", "menuitem2", "menuitem3", "menuitem4", 

                      "menuitem5", "menuitem6", "menuitem7"]

        for item in menu_items:

            btn = tk.Button(self.menu_frame, text=item, bg="#333333", fg="white", 

                            font=("Arial", 12), bd=0, anchor="w",

                            command=lambda i=item: print(f"{i} clicked"))

            btn.pack(fill="x", pady=10, padx=20)


        # --- Toggle Button ---

        self.toggle_btn = tk.Button(self.root, text="Menu", command=self.toggle_menu, 

                                     bg="white", font=("Arial", 12))

        self.toggle_btn.place(x=10, y=10)


    def toggle_menu(self):

        if not self.is_open:

            self.slide_in(self.hidden_y)

        else:

            self.slide_out(self.visible_y)


    def slide_in(self, y_pos):

        if y_pos > self.visible_y:

            y_pos -= 20 # Speed of slide

            self.menu_frame.place(x=0, y=y_pos)

            self.root.after(10, lambda: self.slide_in(y_pos))

        else:

            self.is_open = True


    def slide_out(self, y_pos):

        if y_pos < self.hidden_y:

            y_pos += 20 # Speed of slide

            self.menu_frame.place(x=0, y=y_pos)

            self.root.after(10, lambda: self.slide_out(y_pos))

        else:

            self.menu_frame.place(x=-self.menu_width, y=self.hidden_y)

            self.is_open = False


if __name__ == "__main__":

    root = tk.Tk()

    app = SlidingMenuApp(root)

    root.mainloop()

Jumat, 17 April 2026

Python Menu

 



import tkinter as tk

from tkinter import messagebox


# -------------------------------

# Sliding Menu Application Class

# -------------------------------

class SlidingMenuApp:

    def __init__(self, root):

        self.root = root

        self.root.title("Sliding Menu Example")

        self.root.geometry("600x400")

        self.root.config(bg="white")


        # Menu state

        self.menu_width = 200

        self.menu_current_x = -self.menu_width

        self.menu_target_x = -self.menu_width

        self.menu_speed = 20  # pixels per frame


        # Create menu frame (hidden initially)

        self.menu_frame = tk.Frame(self.root, bg="#2c3e50", width=self.menu_width, height=400)

        self.menu_frame.place(x=self.menu_current_x, y=0)


        # Add menu items

        self.add_menu_items()


        # Create toggle button on the right side

        self.toggle_btn = tk.Button(

            self.root, text="☰", font=("Arial", 14, "bold"),

            bg="#3498db", fg="white", command=self.toggle_menu

        )

        self.toggle_btn.place(relx=1.0, x=-40, y=10, anchor="ne")


        # Start animation loop

        self.animate()


    def add_menu_items(self):

        """Add menu buttons."""

        menu_items = [

            ("Home", lambda: self.show_message("Home")),

            ("Information", lambda: self.show_message("Information")),

            ("Activities", lambda: self.show_message("Activities")),

            ("Feedback", lambda: self.show_message("Feedback")),

        ]

        for i, (text, cmd) in enumerate(menu_items):

            btn = tk.Button(

                self.menu_frame, text=text, font=("Arial", 12),

                bg="#34495e", fg="white", relief="flat", command=cmd

            )

            btn.place(x=10, y=20 + i * 50, width=self.menu_width - 20, height=40)


    def show_message(self, title):

        """Show a message box for menu item."""

        messagebox.showinfo("Menu Clicked", f"You clicked: {title}")


    def toggle_menu(self):

        """Toggle menu open/close."""

        if self.menu_target_x < 0:

            self.menu_target_x = 0  # open

        else:

            self.menu_target_x = -self.menu_width  # close


    def animate(self):

        """Smoothly animate menu sliding."""

        if self.menu_current_x < self.menu_target_x:

            self.menu_current_x += self.menu_speed

            if self.menu_current_x > self.menu_target_x:

                self.menu_current_x = self.menu_target_x

        elif self.menu_current_x > self.menu_target_x:

            self.menu_current_x -= self.menu_speed

            if self.menu_current_x < self.menu_target_x:

                self.menu_current_x = self.menu_target_x


        # Update menu position

        self.menu_frame.place(x=self.menu_current_x, y=0)


        # Repeat animation

        self.root.after(15, self.animate)



# -------------------------------

# Run the Application

# -------------------------------

if __name__ == "__main__":

    root = tk.Tk()

    app = SlidingMenuApp(root)

    root.mainloop()


Lagu cina

 《误闯天家》超燃版

女生戏腔惊艳众人的瞬间


Sabtu, 11 April 2026

Jumat, 10 April 2026

Python Animation Wheel Of Colors

 



import tkinter as tk


def rotate_wheel():

    global current_angle

    current_angle = (current_angle + speed) % 360

    

    # Update each sector's starting angle

    for i, sector in enumerate(sectors):

        start_pos = (current_angle + i * (360 / num_sectors)) % 360

        canvas.itemconfig(sector, start=start_pos)

    

    # Schedule the next update (approx 60 FPS)

    root.after(16, rotate_wheel)


root = tk.Tk()

canvas = tk.Canvas(root, width=400, height=400, bg='white')

canvas.pack()


num_sectors = 8

sectors = []

colors = ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'cyan']

current_angle = 0

speed = 5  # Degrees per frame


# Initialize the wheel sectors

for i in range(num_sectors):

    angle_extent = 360 / num_sectors

    arc = canvas.create_arc(50, 50, 350, 350, 

                            start=i * angle_extent, 

                            extent=angle_extent, 

                            fill=colors[i % len(colors)])

    sectors.append(arc)


rotate_wheel()

root.mainloop()

Rabu, 01 April 2026

VB 6

 https://xxxmen.github.io/vb6/Promsvb6.htm?utm_source=openai


VB 6 Self Typing Demo 2

 

Option Explicit

 

Private Const FIXED_TEXT = "This is a demo of self a typing textbox effect."

 

Private Sub Form_Load()

    Timer1.Interval = 300

End Sub

 

Private Sub Timer1_Timer()

Timer1.Interval = 150 * Rnd

Static i%

 

    i = i + 1

    Text1.Text = Text1.Text & Mid(FIXED_TEXT, i, 1)

    If Text1.Text = FIXED_TEXT Then Timer1.Enabled = False

 

End Sub


VB 6 Self Typing Demo

 


Option Explicit
 
Private Const FIXED_TEXT = "This is a demo of selftyping textbox."
 
Private Sub Form_Load()
    Timer1.Interval = 100
End Sub
 
Private Sub Timer1_Timer()
Static i%
 
    i = i + 1
    Text1.Text = Text1.Text & Mid(FIXED_TEXT, i, 1)
    If Text1.Text = FIXED_TEXT Then Timer1.Enabled = False
 
End Sub


C++ From Year 1995 Bonus

 // Filename: BPROJ1.CPP

// This program displays the character for each ASCII value


#include <iostream.h>


void main()

  {

    // Output a heading

    cout << "Value   Character" << endl;

    

    // For all the characters (missing out the first

    // few unprintable characters.

    for (int i = 32; i <= 255; i++)

      {

         // Make the value print in 3 characters

         cout.width(3);

         // Print the value, followed by some spaces

         // followed by the character value and

         // finally a new line

         cout << i << "     " << (char)i << endl;

      }

  }

=====================

// Filename: BPROJ2.CPP

// This program demonstrates the basic structure

// of a C++ program 

#include <iostream.h>


void main()

  {

    // Declare and initialise variables

    int value1 = 10;

    int value2 = 20;

    int value3 = 40;                   

    // Declare a variable for working out the

    // sum of the numbers

    int sum;             

    // Declare another variable for the result

    int average;                              

    // Add three numbers into sum

    sum = value1 + value2 + value3;

    // divide the sum by the number of values to

    // get the average

    average = sum / 3;

    // Output the result

    cout << "The average of " << value1 << ", "

         << value2 << " and " << value3 << " is "

         << average << endl;

    cout << "The sum of the numbers is " << sum;        

  }

=====================

// BPROJ3.CPP 

// A simple review of character and numeric

// input and output.

#include <iostream.h>


void main()

  {

    // Declare variables

    int decimals = 0;

    float number;

    const int descLen = 80;

    char numberDesc[descLen];

           

    cout << "Enter a floating point number: ";

    cin >> number;

    cin.ignore(80,'\n');

    

    cout << "How many decimal places do you want? ";

    cin >> decimals;

    cin.ignore(80,'\n');

    

    cout << "How do you want to describe the number?" << endl;

    cin.getline(numberDesc,descLen);

    

    cout << endl;

    cout << numberDesc << ": ";

    

    // Format the number as requested

    cout.precision(decimals);

    cout.setf(ios::fixed);

    cout.setf(ios::showpoint);

    

    cout << number;

  }

=====================

// Filename : BPROJ4.CPP

// This project does some calculations

// and then tests them.


#include <iostream.h>


void main()

  {

    char burgerType = ' ';        

    char cheese = ' ';

    char fries = ' ';

    float burgerCost = 0.0F;

    float friesCost = 0.0F;

    float totalCost = 0.0F;

    

    cout << "Welcome to Spencer's Burger Bar!" << endl;

    

    cout << endl << "What sort of burger would you like?" << endl;

    cout << "[s]mall, [q]uarter pounder, [b]loatburger? ";

    cin >> burgerType;

    if (burgerType >= 'a' && burgerType <= 'z')

      burgerType += 'A' - 'a';

    if (burgerType != 'S' &&   burgerType != 'Q'

        && burgerType != 'B')

      burgerType = 'Q';

      

    cout << "Is that with cheese?";    

    cin >> cheese;

    if (cheese == 'Y' || cheese == 'y')

      cheese = 'Y';

    else

      cheese = 'N';

    

    cout << "[r]egular or [l]arge fries?";

    cin >> fries;

    if (fries == 'r' || fries == 'R' ||

        fries == 'l' || fries == 'L')

      {

        if (fries == 'r' || fries == 'l')

          fries += 'A' - 'a';

      }

    else

      fries = 'R';

     

    // Calculate cost - everything is relative

    

    burgerCost = 1.75F;

    if (burgerType == 'S')

      burgerCost *= 0.60F;

    if (burgerType == 'B')

      burgerCost *= 1.7F;                   

    if (cheese == 'Y')

      burgerCost += 0.50F;

      

    if (fries == 'R')

      friesCost = 1.00F;

    else

      friesCost = 1.50F;

      

    totalCost = burgerCost + friesCost;

    

    if (fries == 'L' && burgerType == 'B')

      {

        cout << "There is a special on the Bloat & large fries!" << endl;

        totalCost = totalCost * 0.9F;

      }

      

    cout << "That will be $";

    cout.setf(ios::fixed);

    cout.setf(ios::showpoint);

    cout.precision(2);

    cout << totalCost << "." << endl;

    cout << "Have a nice day!";

  }    

     

      

      

        

  =======================

// BPROJ5.CPP

// Switching and calculations explored

#include <iostream.h>


void main()

  {

    int method = 1;

    float f = 1.99F;

    int i = 10;

    float answer = 0;

    // This program simply demonstrates some rounding errors

    cout << "1. i * f" << endl;

    cout << "2. (int)(i * f)" << endl;

    cout << "3. i * (int)f" << endl;

    cout << "4. (int)(i * f) * f" << endl;

    cout << "5. (int)(i *f) * (int)f" << endl;

    cout << "Enter method: ";

    cin >> method;

    switch (method)

      {

        case 1:

          answer = i * f;

          break;

        case 2:

          answer = (int)(i * f);

          break;

        case 3: 

          answer = i * (int)f;

          break;              

        case 4:

          answer = (int)(i * f) * f;

          break;

        case 5:

          answer = (int)(i * f) * (int)f;

          break;

        default:

          cout << "Invalid input";

          return;

      } 

      

    cout << "The answer is " << answer << endl;

  }

============================

// Filename: BPROJ6.CPP

// Factors - a factor is a number that

// multiplied by another number exactly makes another number


#include <iostream.h>


void main()

  {

    int product = 1;

    while (product)

      {

        cout << endl << "Enter number to test:";

        cin >> product;

        if (product)

          {

             cout << "The factors of " << product << " are:" << endl;

             for (int i = 2; i < product ; i++)

               {

                 if (product % i)

                   continue;

                 cout << i << endl;

               }

          }

      }

  }

        

==============================
// Filename: BPROJ7.CPP
// Exporing function calls at the burger bar
#include <iostream.h>

inline char UpperCase(char c)
  {
    if (c >= 'a' && c <= 'z')
      return c + 'A' - 'a';
    else
      return c;
  }  
      
float PriceBurger(char burgerType,int withCheese)
  {        
    float burgerCost = 1.75F;
    if (burgerType == 'S')
      burgerCost *= 0.60F;
    if (burgerType == 'B')
      burgerCost *= 1.7F;                   
    if (withCheese)
      burgerCost += 0.50F;
    return burgerCost;  
  }  
  
float PriceFries(char fries)
  {
    if (fries == 'R')
      return 1.00F;
    else
      return 1.50F;
  }  
  
void GetBurgerType(char& burgerType, char& cheese)
  {    
    do
      {
         cout << endl << "What sort of burger would you like?" << endl;
         cout << "[s]mall, [q]uarter pounder, [b]loatburger? ";
         cin >> burgerType;
         burgerType = UpperCase(burgerType);
      }
    while (burgerType != 'S' &&   burgerType != 'Q'
           && burgerType != 'B');
      
    do
      {
         cout << "Is that with cheese?";    
         cin >> cheese;             
         cheese = UpperCase(cheese);
       }
    while (cheese != 'Y' && cheese != 'N');
  }

char GetFries()
  {    
    char fries;
    do
      {
         cout << "[r]egular or [l]arge fries?";
         cin >> fries;
         fries = UpperCase(fries);
      }
    while (fries != 'R' && fries != 'L');
    return fries;
  }
    
void Special(char fries, char burgerType, float& totalCost)
  {
    if (fries == 'L' && burgerType == 'B')
      {
        cout << "There is a special on the Bloat & large fries!" << endl;
        totalCost = totalCost * 0.9F;
      }
  }      

void main()
  {
    char burgerType;
    char cheese;
    
    cout << "Welcome to Spencer's Burger Bar!" << endl;
    GetBurgerType(burgerType,cheese);        
    char fries = GetFries();
    float totalCost = PriceBurger(burgerType, (cheese == 'Y')) 
                    + PriceFries(fries);
    Special(fries,burgerType,totalCost);
    cout << "That will be $";
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout << totalCost << "." << endl;
    cout << "Have a nice day!";
  }    
  =============================
// File name: BPROJ8.CPP
// Something interesting with arrays and pointers.

#include <iostream.h>

// A routine to return a value 0 for non-alpha
// and 1 to 26 for a to z in either upper or lowercase
inline int Letters(char p)
  {
    if (p >= 'a' && p <= 'z')
      return p - 'a' + 1;
    if (p >= 'A' && p <= 'Z')
      return p - 'A' + 1;
    else
      return 0;
  }
        

void main()
  {
    const int maxLen = 80;
    char input[maxLen];
    int letters[27] = {0};
    
    char * inpPtr;
    cout << "Give me a string please" << endl;
    cin.getline(input,maxLen);
    
    inpPtr = input;
    
    while (*inpPtr)  // While not string terminator
      letters[Letters(*inpPtr++)]++;  // !!! Guess what this does !!!  
    
    cout << "Your string contains: " << endl;
    cout << "Non-alpha " << letters[0] << endl;
    for (int i = 1; i < 27; i++)
      if (letters[i])
        cout << (char)('A' + i - 1) << "         "
             << letters[i] << endl;
  }

C++ From Year 1995 Extras

 // Filename: BIT1.CPP

// Demonstrate &, |, ^, and ~ on two values

#include <iostream.h>

void main()

{

  int i = 5, j = 12;

  int answer;

  // Although this program applies the bitwise operators to

  // variables, bitwise operators also work on literal values


  answer = i & j;

  cout << "The result of i & j is " << answer << endl;


  answer = i | j;

  cout << "The result of i | j is " << answer << endl;


  answer = i ^ j;

  cout << "The result of i ^ j is " << answer << endl;


  // Notice how ~ takes only a single argument

  answer = ~i;

  cout << "The result of ~i is " << answer << endl;

  answer = ~j;

  cout << "The result of ~j is " << answer << endl;


  return;

}

===========================

// Filename: BITEQUI2.CPP

// Uses bitwise operators to work with user input

#include <iostream.h>

void main()

{

  int i, result;

  char c;


  cout << "Enter a number and I'll say if it's odd or even: ";

  cin >> i;


  if (i & 1)

    { cout << "The number is odd" << endl; }

  else

    { cout << "The number is even" << endl; }


  cout << endl << "Enter a number that you want multiplied by 32: ";

  cin >> i;

  result = i << 5;  // Multiplies by 2 raised to the 5th power

  cout << i << " times 32 is " << result << endl;


  result = i >> 3;

  cout << i << " divided by 8 is " << result << endl;


  cout << endl << "Please enter your first initial: ";

  cin >> c;

  if (c & 32)

    { cout << "Always type your initial in uppercase" << endl; }

  else

    { cout << "You entered the initial in uppercase, good!" << endl; }


  return;

}

========================

// Filename: BITEQUIV.CPP

// Uses bitwise operators to work with user input

#include <iostream.h>

void main()

{

  int i, result;

  char c;


  cout << "Enter a number and I'll say if it's odd or even: ";

  cin >> i;


  if ((i & 1) == 1)

    { cout << "The number is odd" << endl; }

  else

    { cout << "The number is even" << endl; }


  cout << endl << "Enter a number that you want multiplied by 32: ";

  cin >> i;

  result = i << 5;   // Multiply by 2 raised to the fifth power

  cout << i << " times 32 is " << result << endl;


  cout << endl << "Please enter your first initial: ";

  cin >> c;

  if (c & 32)

    { cout << "Always type your initial in uppercase" << endl; }

  else

    { cout << "You entered the initial in uppercase, good!" << endl; }


  return;

}

=========================

// Filename: BITSHIFT.CPP

// Shows the results of several bitwise shift operations

#include <iostream.h>

void main()

{

  int shiftResult;


  shiftResult = 13 << 2;

  cout << "13 << 2 is " << shiftResult << endl;


  shiftResult = 13 >> 2;

  cout << "13 >> 2 is " << shiftResult << endl;


  shiftResult = -13 << 2;

  cout << "-13 << 2 is " << shiftResult << endl;


  shiftResult = -13 >> 2;

  cout << "-13 >> 2 is " << shiftResult << endl;


  return;

}

======================

// Filename: BONUSP1.CPP

// Shows how the advanced operators give

// you more control and efficiency

#include <iostream.h>


const int MAKEUPPER = 223;


void main()

{

  char partCode;

  int num, doubleNum;

  float price;

  double totalInv;


  cout << "** Inventory Valuation **" << endl << endl;

  cout << "What is the character part code? ";

  cin >> partCode;

  

  partCode &= MAKEUPPER;   // Ensure that the part

                           // code is uppercase


  cout << "How many parts are there? ";

  cin >> num;

  cout << "What is the price of each part? ";

  cin >> price;


  cout.precision(2);

  cout.setf(ios::showpoint);

  cout.setf(ios::fixed);

  totalInv = (double)num * (double)price;

  cout << endl << "For part code " << partCode << ", ";

  cout << "the total valuation is $" << totalInv << endl;


  doubleNum = num << 1;   // Compute double the current number

  cout << endl << "Doubling our inventory would give us "

       << doubleNum << " new parts" << endl;

  (num < 20) ? cout << endl << "We need to order more inventory!" 

                    << endl

             :

               cout << endl << "We now have enough inventory"

                    << endl;

 }

================

// Filename: ORANGE.CPP

// See if the user likes orange juice

#include <iostream.h>


void main()

{

  const int UPMASK = 223;

  char ans;


  cout << "Do you like fresh squeeze orange juice (Y/N)? ";

  cin >> ans;


  ans &= UPMASK;  // Convert to uppercase

  if (ans == 'Y')

    { cout << "You'll be healthy all your life!" << endl; }

  else

    { cout << "You need the vitamin C!" << endl; }


  return;

}