switchcaseを使用してライブラリ管理システムのCプログラムを作成する
問題
Cプログラミングを使用して図書館の本関連情報を保存する方法。
アルゴリズム
Step 1: Declare a structure which holds data members Step 2: declare variables which are used for loop Step 3: use switch case to work on each module Step 4: case 1- for Adding book information Case 2- for Display book information Case 3- for Finding number for books in library Case 4- for EXIT
プログラム
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct library{
char bookname[50];
char author[50];
int noofpages;
float price;
};
int main(){
struct library lib[100];
char bookname[30];
int i,j, keepcount;
i=j=keepcount = 0;
while(j!=6){
printf("\n1. Add book information\n");
printf("2.Display book information\n");
printf("3. no of books in the library\n");
printf("4. Exit");
printf ("\n\nEnter one of the above : ");
scanf("%d",&j);
switch (j){
/* Add book */
case 1:
printf ("Enter book name = ");
scanf ("%s",lib[i].bookname);
printf ("Enter author name = ");
scanf ("%s",lib[i].author);
printf ("Enter pages = ");
scanf ("%d",&lib[i].noofpages);
printf ("Enter price = ");
scanf ("%f",&lib[i].price);
keepcount++;
i++;
break;
case 2:
printf("you have entered the following information\n");
for(i=0; i<keepcount; i++){
printf ("book name = %s\n",lib[i].bookname);
printf ("\t author name = %s\n",lib[i].author);
printf ("\t pages = %d\n",lib[i].noofpages);
printf ("\t price = %f\n",lib[i].price);
}
break;
case 3:
printf("\n No of books in library : %d", keepcount);
break;
case 4:
exit (0);
}
}
return 0;
} 出力
1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 1 Enter book name = HarryPotter Enter author name = hp Enter pages = 250 Enter price = 350.6 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 2 you have entered the following information book name = HarryPotter author name = hp pages = 250 price = 350.600006 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 3 No of books in library : 1 1. Add book information 2.Display book information 3. no of books in the library 4. Exit Enter one of the above : 4
-
time.hライブラリ関数を使用してCプログラムを作成します
問題 Cプログラミング言語を使用して現在の日付と時刻をISO標準形式で表示するにはどうすればよいですか? 解決策 入力の現在の日付と時刻が取得され、システムの時刻と日付をISO形式で印刷しようとしています。 たとえば、2020年12月15日月曜日10.50p。 このプログラムで使用した組み込み関数は-です。 Time() −現在の時刻を返します。 Strftime() −時間を文字列形式に変換します。この関数はtime.hに含まれます。 例 #include<stdio.h> #include<time.h> int main(){ &nb
-
strncmpライブラリ関数を使用して2つの文字列を比較するCプログラムを作成します
Strncmpは、string.hファイルに存在する事前定義されたライブラリ関数であり、2つの文字列を比較し、どちらの文字列が大きいかを表示するために使用されます。 strcmp機能(文字列比較) この関数は2つの文字列を比較します。両方の文字列の最初の2つの一致しない文字のASCIIの違いを返します。 構文 int strcmp (string1, string2); 差がゼロに等しい場合、string1=string2。 string2。 差が負の場合、string1