Thuta Learning
ရှာဖွေရန်
ProjectsProgrammingbeginner

Mini Project: Student Manager - Part 1

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Mini Project: Student Manager - Part 1 ကို လက်တွေ့ project ထဲမှာ အသုံးချတတ်မယ်
  • ကိုယ်တိုင် code ရေးပြီး run ကြည့်တတ်မယ်
  • Project တစ်ခုလုံးကို အဆင့်လိုက် ဆောက်တတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ project မှာ Basic chapter က variable, function, loop အကြောင်း၊ Intermediate chapter က array, pointer, reference အကြောင်း၊ Advanced chapter က class, object, access specifier အကြောင်း သင်ခဲ့တာတွေအားလုံးကို ပေါင်းစပ်သုံးပြီး Student Record Manager လို့ခေါ်တဲ့ small console application တစ်ခု တည်ဆောက်ပါမယ်။ Part 1 မှာတော့ program ရဲ့ foundation ဖြစ်တဲ့ Student class ကို design လုပ်ပြီး, private data member တွေကို encapsulation နည်းနဲ့ ကာကွယ်ပြီး public method တွေကနေပဲ access ဖြစ်အောင်စီစဉ်ပါမယ်။ vector<Student> ကို သုံးပြီး student list တစ်ခုလုံးကို memory ထဲမှာ dynamic ဖြစ်အောင် သိမ်းထားမှာပါ။ info Part 2 မှာ add/search/display feature တွေ ထည့်မှာဖြစ်ပြီး Part 3 မှာ file save/load နဲ့ error handling နဲ့ project ပြီးအောင် ပြီးစီးပါမယ်။

လက်တွေ့ ဆောက်ကြည့်မယ်

Student class ကို name (string), roll (int), marks (double) ဆိုပြီး private member 3 ခုနဲ့ တည်ဆောက်ပါ။ Constructor တစ်ခုနဲ့ getName(), getRoll(), getMarks() လို getter method တွေကို public အောက်မှာထားပါ။ main() function ထဲမှာ vector<Student> students; declare လုပ်ပြီး, menu loop တစ်ခုကို while(true) နဲ့ ဖန်တီးပါ - user ကို 1) Add Student 2) Display All 3) Exit ဆိုပြီး choice ပြပါ။ switch statement နဲ့ user ရွေးချယ်မှုအလိုက် function တွေခေါ်နိုင်အောင် skeleton ချထားပါ - Part 2 မှာ logic တွေ ဆက်ဖြည့်သွားပါမယ်။

Code နမူနာ

cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Student {
private:
    string name;
    int roll;
    double marks;

public:
    Student(string n, int r, double m) {
        name = n;
        roll = r;
        marks = m;
    }

    string getName() const { return name; }
    int getRoll() const { return roll; }
    double getMarks() const { return marks; }
};

int main() {
    vector<Student> students;
    int choice;

    while (true) {
        cout << "\n--- Student Manager ---\n";
        cout << "1. Add Student\n";
        cout << "2. Display All\n";
        cout << "3. Exit\n";
        cout << "Choice: ";
        cin >> choice;

        switch (choice) {
            case 1:
                // Part 2 မှာ ဖြည့်ပါမယ်
                break;
            case 2:
                // Part 2 မှာ ဖြည့်ပါမယ်
                break;
            case 3:
                cout << "Goodbye!\n";
                return 0;
            default:
                cout << "Invalid choice!\n";
        }
    }
}
You should see
Program run ရင် menu 3 ခု ပြပြီး, choice 3 ရွေးလိုက်ရင် "Goodbye!" ပြပြီး program ပြီးဆုံးသွားမှာဖြစ်ပါတယ်။

၅ မိနစ် စမ်းကြည့်

Student class ထဲမှာ setMarks(double newMarks) ဆိုတဲ့ setter method တစ်ခု ထပ်ထည့်ပြီး marks ကို update လုပ်နိုင်အောင် ကြိုးစားကြည့်ပါ။

သတိလေးတစ်ချက်

Encapsulation ကို အစကတည်းက သေချာစီစဉ်ထားမှ Part 2, 3 မှာ code ပိုင်းတွေ ထပ်ပေါင်းရင် ချောမွေ့ပါမယ်။ getter/setter pattern ကို ဒီအတိုင်း အစဉ်လိုက်ထားပါ။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Data member တွေကို private ထားရမယ့်အစား public ထားပြီး direct access ဖြစ်အောင်လုပ်တတ်တာ - encapsulation ပျက်စီးသွားပါတယ်
  • vector<Student> ကို main() ရဲ့ scope ထဲပဲ declare လုပ်လိုက်ပြီး function တွေကနေ ဘယ်လို access လုပ်မလဲဆိုတာ စဉ်းစားမထားတာ

အခု ကိုယ်တိုင် စမ်းကြည့်

Student class ထဲမှာ setMarks(double newMarks) ဆိုတဲ့ setter method တစ်ခု ထပ်ထည့်ပြီး marks ကို update လုပ်နိုင်အောင် ကြိုးစားကြည့်ပါ။

You'll know it worked when: Program run ရင် menu 3 ခု ပြပြီး, choice 3 ရွေးလိုက်ရင် "Goodbye!" ပြပြီး program ပြီးဆုံးသွားမှာဖြစ်ပါတယ်။

Mini Project: Student Manager - Part 1 | Thuta Learning