linux系统及编程基础课后答案 下载本文

{

have_dot=TRUE;

i=g_strlcat(number,\

gtk_entry_set_text(GTK_ENTRY(entry),number); } }

void on_clear_clicked(GtkButton *button,gpointer data) {

clear_all(); }

void on_suan_clicked(GtkButton *button,gpointer data) {

gint i;

switch(GPOINTER_TO_INT(data)) {

case 1:

gtk_entry_set_text(GTK_ENTRY(entry),\ s=1; first=FALSE; count=0; break; case 2:

gtk_entry_set_text(GTK_ENTRY(entry),\ s=2; first=FALSE; count=0; break; case 3:

gtk_entry_set_text(GTK_ENTRY(entry),\ s=3; first=FALSE; count=0; break; case 4:

gtk_entry_set_text(GTK_ENTRY(entry),\ s=4; first=FALSE; count=0; break; }

have_dot=FALSE;

for(i=0;i<100;i++) number[i]='\\0'; }

void on_eq_clicked(GtkButton *button,gpointer data) {

double numb; gchar *result; gchar num[100]; switch(s) {

case 1:

numb=nn+mm; break; case 2:

numb=nn-mm; break; case 3:

numb=nn*mm; break; case 4:

if(mm==0) {

gtk_entry_set_text(GTK_ENTRY(entry),\ break; }

numb=nn/mm; break; }

result=g_ascii_dtostr(num,100,numb); gtk_entry_set_text(GTK_ENTRY(entry),result); have_result=TRUE; }

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

GtkWidget *window; GtkWidget *vbox;

GtkWidget *hbox,*hbox1,*hbox2,*hbox3,*hbox4; GtkWidget *button; GtkWidget *label; GtkWidget *label1;

gtk_init(&argc,&argv);

window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window),500,300); gtk_container_set_border_width(GTK_CONTAINER(window),10); gtk_window_set_title(GTK_WINDOW(window),\计算器\

gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);

g_signal_connect(G_OBJECT(window),\

vbox=gtk_vbox_new(TRUE,0);

gtk_container_add(GTK_CONTAINER(window),vbox); hbox=gtk_hbox_new(TRUE,0);

gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,5); label=gtk_label_new(\

gtk_box_pack_start(GTK_BOX(hbox),label,TRUE,TRUE,5); label1=gtk_label_new(\

gtk_box_pack_start(GTK_BOX(hbox),label1,TRUE,TRUE,5);

time_t now;

struct tm *l_time; gchar buf[100];

now=time((time_t *)NULL); l_time=localtime(&now);

sprintf(buf,\ gtk_label_set_text(GTK_LABEL(label1),buf);

button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\

entry=gtk_entry_new();

gtk_editable_set_editable(GTK_EDITABLE(entry),FALSE); gtk_widget_set_direction(entry,GTK_TEXT_DIR_RTL); gtk_box_pack_start(GTK_BOX(vbox),entry,TRUE,TRUE,5);

hbox1=gtk_hbox_new(FALSE,0);

gtk_box_pack_start(GTK_BOX(vbox),hbox1,TRUE,TRUE,5); button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox1),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox1),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox1),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox1),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\

hbox2=gtk_hbox_new(FALSE,0);

gtk_box_pack_start(GTK_BOX(vbox),hbox2,TRUE,TRUE,5); button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox2),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox2),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox2),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox2),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\

hbox3=gtk_hbox_new(FALSE,0);

gtk_box_pack_start(GTK_BOX(vbox),hbox3,TRUE,TRUE,5); button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox3),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox3),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox3),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\ button=gtk_button_new_with_label(\

gtk_box_pack_start(GTK_BOX(hbox3),button,TRUE,TRUE,5);

g_signal_connect(G_OBJECT(button),\

hbox4=gtk_hbox_new(FALSE,0);