Xorazmiy nomidagi toshkent axborot texnologiyalari universiteti samarqand filiali “telekommunikatsiya texnologiyalari va kasb ta’limi” fakulteti




Download 363,5 Kb.
bet2/2
Sana21.05.2024
Hajmi363,5 Kb.
#248071
1   2
Bog'liq
Qanoatova Nurxon Dasturlash 2 fanidan 4-mustaqil is

push(item): Stackga yangi ma'lumotni qo'shadi. Bu funksiya o'z ichiga bir ma'lumotni qabul qiladi va uningni stackning oxiriga qo'shadigan.

  • pop(): Stackning eng ustidagi ma'lumotni o'chiradi va uni qaytaradi. Bu funksiya stackning oxirgi elementini o'chiradi va uni qaytaradi. Agar stack bo'sh bo'lsa, "Stack bo'sh" deb qaytariladi.

  • top(): Stackning eng ustidagi ma'lumotni qaytaradi, lekin o'chirmaydi. Bu funksiya stackning oxirgi elementini qaytaradi, lekin stackni o'zgarmas qiladi.

  • size(): Stackdagi elementlar sonini qaytaradi.

  • empty(): Stack bo'sh bo'lsa True, aks holda False qaytaradi.

    2-topshiriq. 1-masala.


    Lotin harflaridan iborat S satr berilgan.Satrdagi barcha unli(“a, “i”, “u”, “e”, “o”)belgilarini o’chirib hosil bo’lgan natija satrni chiqaring. S satr uzunligi kamida 20 ta belgi.
    #include
    #include

    using namespace std;

    string ochir_unli(string satr) {
    // Unli harflar ro'yxati
    string unli_harflar = "aeiouAEIOU";
    string natija = ""; // Yangi satr uchun bo'sh string
    for (char harf : satr) {
    // Agar harf unli harflar ro'yxatida bo'lmasa, uni natijaga qo'shamiz
    if (unli_harflar.find(harf) == string::npos) {
    natija += harf;
    }
    }
    return natija; // Yangi satrni qaytarish
    }

    int main() {


    // Sizning S satr
    string S = "Lotin harflaridan iborat S satr berilgan. Satrdagi barcha unli belgilarini o’chirib hosil bo’lgan natija satrni chiqaring.";

    // S satr uzunligini tekshirish


    if (S.length() < 20) {
    cout << "S satrining uzunligi kamida 20 belgi bo'lishi kerak!" << endl;
    return 1; // Dastur bekor qilinadi
    }

    // Natijani chiqarish


    string natija_satr = ochir_unli(S);
    cout << "Asl satr: " << S << endl;
    cout << "O'chirilgan unli harflardan keyingi natija satr: " << natija_satr << endl;

    return 0;


    }
    Natijasi:

    3-topshiriq. 5-misol
    Visual Studio C++ da geometrik shakillarni chizishga doir misol keltiring. Masalan, DrawEllipse funksiyasi yordamida aylana chizing (chiziq rangi qora).
    5-Misol

    #include

    // Function to draw a circle


    static void draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
    // Set the line color to green
    cairo_set_source_rgb(cr, 0, 1, 0);

    // Set the line width


    cairo_set_line_width(cr, 2.0);

    // Define the center and radius of the circle


    double centerX = 200.0;
    double centerY = 200.0;
    double radius = 100.0;

    // Draw the circle


    cairo_arc(cr, centerX, centerY, radius, 0, 2 * G_PI);
    // Stroke the path (draw the circle)
    cairo_stroke(cr);
    }

    // Callback function for the button click event


    static void on_button_clicked(GtkWidget *button, gpointer user_data) {
    GtkWidget *drawing_area = GTK_WIDGET(user_data);
    gtk_widget_queue_draw(drawing_area); // Queue the drawing area to be redrawn
    }

    int main(int argc, char *argv[]) {


    gtk_init(&argc, &argv);

    // Create the main window


    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Draw Circle");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    // Create a vertical box container


    GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    // Create a button


    GtkWidget *button = gtk_button_new_with_label("Draw Circle");
    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);

    // Create a drawing area


    GtkWidget *drawing_area = gtk_drawing_area_new();
    gtk_widget_set_size_request(drawing_area, 400, 400);
    gtk_box_pack_start(GTK_BOX(vbox), drawing_area, TRUE, TRUE, 0);

    // Connect the draw callback to the drawing area


    g_signal_connect(G_OBJECT(drawing_area), "draw", G_CALLBACK(draw_callback), NULL);

    // Connect the button click event to the callback


    g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), drawing_area);

    // Show all widgets


    gtk_widget_show_all(window);

    gtk_main();



    return 0;
    }

    Natija:

    Download 363,5 Kb.
  • 1   2




    Download 363,5 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Xorazmiy nomidagi toshkent axborot texnologiyalari universiteti samarqand filiali “telekommunikatsiya texnologiyalari va kasb ta’limi” fakulteti

    Download 363,5 Kb.