1.java怎么定义一个对象?
2.c语言图书管理系统
3.Cè¯è¨å®ç°å¾ä¹¦ç®¡çç³»ç»
java怎么定义一个对象?
你应该问怎么实例化一个类生成一个对象java 是源码先定义一个类 ,然后new 这个类,源码然后生成对象的源码
Java编程中类和对象的定义
1,什么是源码类?
答:类是客观存在的,抽象的源码积分现金商城源码,概念的源码UCosii源码行数东西。
2,源码什么事对象?
答:对象是源码具体的,实际的源码,代表一个事物。源码例如:车是源码一个类,汽车,源码自行车就是源码桃园之都源码他的对象。
关于类与对象的源码描述:类是对象的模版,对象是源码类的一个个体
3,Java中定义类的方法?
class 类名
用Java语法定义人类:
public class Person{
}
4,对象的女巫面具源码定义方法?
1,对象声明:类名 对象名;
2,对象创建 对象名 = new 类名(); new作用:分配内存空间。
也可以合写为:类名 对象名 = new 类名();
5,例子:创建一个空调,aide病毒源码并调用制冷。
//设计一个空调package practice;
public class Kongtiao {
//空调属性
String name;
String pinpai;
String pishu;
int tempeture;
//定义制冷行为
void cool()
{
tempeture--;
}
//定义加热行为
void hot()
{
tempeture+=7;
}
//主函数
public static void main(String[] args){
Kongtiao kt = new Kongtiao();
kt.name = "美的";
kt.pishu = "2匹";
kt.tempeture = ;
kt.pinpai = "志高";
/
**kt.cool();
System.out.println("空调的温度是"+kt.tempeture);
*/
kt.hot();
System.out.println("空调的温度是"+kt.tempeture);
}
}
c语言图书管理系统
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
typedef int BOOL;
typedef struct bookinfo
{
char number[];/*产品编号*/
char name[];/*产品名称*/
float price;/*单价*/
char auther[];/*作者*/
BOOL isExit;/*存在状态*/
char lendername[];/*借书人姓名*/
char lendersex[2];/*借书人性别*/
char lendernum[];/*借书人学号*/
}BOOKINFO;
void menu()
{
printf("\n\n\n\n\n\n\n");
printf("\t\t\t图书管理系统\n");
printf("\t\t\t1:新进图书基本信息的输入\n");
printf("\t\t\t2:显示全部记录\n");
printf("\t\t\t3:根据图书名称查询图书基本信息\n");
printf("\t\t\t4:根据图书名称对撤销的图书信息进行删除\n");
printf("\t\t\t5:按照图书名称从小大到排序\n");
printf("\t\t\t6:统计某价格以上的图书数量\n");
printf("\t\t\t7:列出所有未借出去的图书信息\n");
printf("\t\t\t8:退出\n");
}
void choice_1_input_new()/*输入新进的图书信息*/
{
char choice;
FILE *p;
BOOKINFO newbook;
system("cls");
while(1)
{
printf("输入图书编号:");
gets(newbook.number);
printf("输入图书名称:");
gets(newbook.name);
printf("输入图书单价:");
scanf("%f",&newbook.price);
while(getchar()!='\n');
printf("输入图书的作者:");
gets(newbook.auther);
printf("输入借书人姓名:");
gets(newbook.lendername);
printf("输入借书人性别:");
gets(newbook.lendersex);
printf("输入借书人学号:");
gets(newbook.lendernum);
printf("是否保存该条书目?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
{
newbook.isExit=1;/*将图书状态设置成1,表示没有借出*/
p=fopen("c:\\bookinfo.data","ab");
fwrite(&newbook,sizeof(BOOKINFO),1,p);
fclose(p);
printf("\n该条书目已添加到c:\\bookinfo.data文件中!\n");
}
else
{
printf("\n本条书目未保存!\n");
}
printf("\n是否继续添加书目?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
continue;
else
break;
}
}
void choice_2_display_all()/*显示全部图书信息*/
{
FILE *p;
int n;
BOOKINFO bookinfo[];
int booknumber=0;
system("cls");
p=fopen("c:\\bookinfo.data","rb");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
/*booknumber--;使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
booknumber--;
if(booknumber==0)
{
printf("没有任何图书信息!\n\n");
}
else
{
n=0;
printf(" 图书信息如下\n");
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
while(n<booknumber)
{
printf("%-6s%-s%-8.1f%-8s%-9d| %-s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
n++;
}
}
printf("\n\n按任意键回到主菜单!\n");
getch();
}
void choice_3_search_according_name()/*根据图书名称显示图书的信息*/
{
char search[]="";/*search用来存放要查询的书名*/
int n;
FILE *p;
char choice;
BOOKINFO bookinfo[];
int booknumber=0;
system("cls");
p=fopen("c:\\bookinfo.data","rb");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
while(1)
{
printf("输入要查询的书本名称:");
gets(search);
if(booknumber==0)
{
printf("书库中没有任何信息!\n\n");
printf("按任意键回到主菜单!\n\n");
getch();
break;
}/*if结束*/
else
{
for(n=0;n<booknumber;n++)
if(strcmp(bookinfo[n].name,search)==0)
{
printf("该书的详细信息如下:\n");
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
printf("%-6s%-s%-8.1f%-8s%-9d| %-s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
break;
}
if(n>=booknumber)
printf("没有查找该书的任何信息!\n");
printf("\n\n是否继续查询?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
continue;
else
break;
}/*else结束*/
}/*while(1)结束*/
}
void choice_4_delete_according_name()/*根据图书名称对图书信息进行删除*/
{
char search[]="";/*search用来存放要删除的书名*/
int n,i;
FILE *p;
char choice;
BOOKINFO bookinfo[];
int booknumber;
system("cls");
while(1)
{
printf("输入要删除的书本名称:");
gets(search);
p=fopen("c:\\bookinfo.data","rb");
booknumber=0;
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
if(booknumber==0)
{
printf("书库中没有任何信息!\n\n");
printf("按任意键回到主菜单!\n\n");
getch();
break;
}/*if结束*/
else
{
for(n=0;n<booknumber;n++)
if(strcmp(bookinfo[n].name,search)==0)
{
break;
}
if(n>=booknumber)
printf("没有查找该书的任何信息!\n");
else
{
printf("是否确认需要删除该条书目?(Y/N)");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
{
for(i=n;i<booknumber-1;i++)
bookinfo[i]=bookinfo[i+1];
booknumber--;
p=fopen("c:\\bookinfo.data","wb");
for(n=0;n<booknumber;n++)
fwrite(&bookinfo[n],sizeof(BOOKINFO),1,p);
fclose(p);
printf("删除成功!\n");
}
else
printf("\n\n该条书目没有被删除!");
}
printf("\n\n是否继续进行删除操作?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
continue;
else
break;
}/*else结束*/
}/*while(1)结束*/
}
void choice_5_sort_according_name()/*根据图书名称排序*/
{
FILE *p;
int m,n;
BOOKINFO temp;
BOOKINFO bookinfo[];
int booknumber;
p=fopen("c:\\bookinfo.data","rb");
booknumber=0;
system("cls");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
if(booknumber==0)
{
printf("没有任何图书信息!\n\n");
}
else
{
for(m=0;m<booknumber-1;m++)
for(n=m+1;n<booknumber;n++)
if(strcmp(bookinfo[m].name,bookinfo[n].name)>0)
{
temp=bookinfo[m];
bookinfo[m]=bookinfo[n];
bookinfo[n]=temp;
}
p=fopen("c:\\bookinfo.data","wb");
for(m=0;m<booknumber;m++)
fwrite(&bookinfo[m],sizeof(BOOKINFO),1,p);
fclose(p);
printf("\n\n完成排序!\n\n");
}
printf("按任意键回到主菜单!\n");
getch();
}
void choice_6_display_high_price()/*根据价格列出图书信息*/
{
float price;
FILE *p;
int n;
int count=0;
BOOKINFO bookinfo[];
int booknumber;
system("cls");
printf("请输入价格:");
scanf("%f",&price);
p=fopen("c:\\bookinfo.data","rb");
booknumber=0;
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
if(booknumber==0)
{
printf("没有任何图书信息!\n\n");
}
else
{
for(n=0;n<booknumber;n++)
{
if(bookinfo[n].price>=price)
count++;
}
if(count==0)
printf("书库中没有比%.1f$价格高的图书!",price);
else
{
printf(" 价格高于%.1f$的图书信息如下\n",price);
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
for(n=0;n<booknumber;n++)
{
if(bookinfo[n].price>=price)
printf("%-6s%-s%-8.1f%-8s%-9d| %-s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
}
}
}
printf("\n\n按任意键回到主菜单!\n");
getch();
}
void choice_7_display_according_exitflag()/*根据存在状态列出图书信息*/
{
FILE *p;
int n;
int count=0;
BOOKINFO bookinfo[];
int booknumber;
system("cls");
booknumber=0;
p=fopen("c:\\bookinfo.data","rb");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;
fclose(p);
if(booknumber==0)
{
printf("书库中没有任何书目存在!\n");
}
else
{
for(n=0;n<booknumber;n++)
if(bookinfo[n].isExit==1)
count++;
if(count==0)
printf("书库中的书籍全部借出!\n");
else
{
printf("书库中未被借出的图书信息如下:\n\n");
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
for(n=0;n<booknumber;n++)
if(bookinfo[n].isExit==1)
{
printf("%-6s%-s%-8.1f%-8s%-9d| %-s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
}
}
}
printf("\n按任意键返回主菜单!\n");
getch();
}
void main()
{
char choice;
clock_t tm;
FILE *p;
if((p=fopen("c:\\bookinfo.data","rb"))==NULL)
{
p=fopen("c:\\bookinfo.data","wb");
fclose(p);
}
while(1)
{
system("cls");
menu();
choice=getch();
switch(choice)
{
case '1':choice_1_input_new();break;/*输入新进的图书信息*/
case '2':choice_2_display_all();break;/*显示全部图书信息*/
case '3':choice_3_search_according_name();break;/*根据图书名称显示图书的信息*/
case '4':choice_4_delete_according_name();break;/*根据图书名称对图书信息进行删除*/
case '5':choice_5_sort_according_name();break;/*根据图书名称排序*/
case '6':choice_6_display_high_price();break;/*根据价格列出图书信息*/
case '7':choice_7_display_according_exitflag();break;/*根据存在状态列出图书信息*/
case '8':printf("\n\n\t\t\t谢谢使用,再见!\n\t\t\t按任意键退出!\n");getch();return;
default:
printf("\n\n\t\t\t请输入菜单中的数字!(1~8)");
tm=clock();
while(clock()<tm+);
break;
}
}
}
写的很赶,不知道行不行
程序很长,但是没什么复杂的东西。
要是写的不好,楼主就将就吧。
Cè¯è¨å®ç°å¾ä¹¦ç®¡çç³»ç»
å¾ä¹¦ç®¡çç³»ç»çcå®ç°ç¨äºå¾ä¹¦ä¿¡æ¯ç管çãå æ¬å¾ä¹¦ä¿¡æ¯çå建ãå¾ä¹¦ä¿¡æ¯çæå°ãå¾ä¹¦ä¿¡æ¯çæ¥è¯¢ãå¾ä¹¦ä¿¡æ¯çä¿®æ¹ãå¾ä¹¦ä¿¡æ¯çå é¤ãæ¹ä¾¿ç¨æ·æ´çå¾ä¹¦ï¼æ¥è¯¢å¾ä¹¦ã
è¿ä¸ªå¾ä¹¦ç®¡çç³»ç»æ¯ç±åé¾è¡¨è¿ä¸æ°æ®ç»æå®ç°çï¼æ¿åå æ¬å¾ä¹¦ä¿¡æ¯çå建ãæå°ãæ¥è¯¢ãä¿®æ¹ãå é¤ã以åå¾ä¹¦ä»·æ ¼çæåºçç»æã 代ç åé¢ä¹æ注éçï¼åºæ¬å¾å¥½ç解çã
ä¸é¢ä¸ºæºä»£ç ï¼
#include <stdio.h>#include <stdlib.h>#include <string.h>//3.æ°æ®ç设计//3.1ç¨åºçæ°æ®åå¨--->容å¨//3.2æ°æ®çç»æ --->å¾ä¹¦çä¿¡æ¯struct bookInfo{ char name[];//书åfloat price;//书ç±çä»·æ ¼int num;//书ç±çæ°é};//å®ä¹é¾è¡¨struct Node{ struct bookInfo data;struct Node* next;};struct Node* list = NULL;//å°é¾è¡¨å£°ææå ¨å±åé//å建表头ï¼è¡¨å¤´å°±æ¯ç»æä½åéstruct Node* createHead(){ //å¨æå åç³è¯·struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));//åéåå§åheadNode->next = NULL;return headNode;}//å建èç¹ï¼ä¸ºæå ¥ååå¤// æç¨æ·çæ°æ®åæç»æä½åéstruct Node* createNode(struct bookInfo data){ struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));newNode->data = data;newNode->next = NULL;return newNode;}//æ°æ®æå ¥ï¼å¤´ææ³ï¼void insertNodeByHead(struct Node* headNode, struct bookInfo data){ struct Node* newNode = createNode(data);newNode->next = headNode->next;headNode->next = newNode;}//å°¾ææ³/*struct insertNodeByTall(struct Node* headNode, int data){ struct Node* pMove = headNode;while (pMove != NULL){ pMove = pMove->next;}struct Node* newNode = createHead(data);pMove->next = newNode;}*///æå®å é¤ï¼å é¤é¾è¡¨ä¸å ç´ ï¼//posLeftNode->next=posNode->next;//free(posNode);void deleteNodeByName(struct Node* headNode, char* bookname){ struct Node* posLeftNode = headNode;struct Node* posNode = headNode->next;//书ç±ååæ¯å符串ï¼å符串æ¯è¾å½æ°while (posNode != NULL && strcmp(posNode->data.name, bookname)){ posLeftNode = posNode;posNode = posLeftNode->next;}//讨论æ¥æ¾çç»æif (posNode == NULL)return;else{ printf("å é¤æåï¼\n");posLeftNode->next = posNode->next;free(posNode);posNode = NULL;}}//æ¥æ¾struct Node* searchByName(struct Node* headNode, char* bookName){ struct Node* posNode = headNode->next;while (posNode != NULL && strcmp(posNode->data.name, bookName)){ posNode = posNode->next;}return posNode;}//æå°é¾è¡¨void printList(struct Node* headNode){ struct Node* pMove = headNode->next;printf("书å\tä»·æ ¼\tæ°é\n");while (pMove != NULL){ printf("%s\t%.1f\t%d\n", pMove->data.name, pMove->data.price, pMove->data.num);pMove = pMove->next;}}//ç´æ¥æ件æä½//æ件åæä½void saveInfoToFile(const char* filename, struct Node* headNode){ FILE* fp = fopen(filename, "w");struct Node* pMove = headNode->next;while (pMove != NULL){ fprintf(fp, "%s\t%.1f\t%d\n", pMove->data.name, pMove->data.price, pMove->data.num);pMove = pMove->next;}fclose(fp);}//æ件读æä½void readInfoFromFile(const char* fileName, struct Node* headNode){ FILE* fp = fopen(fileName, "r");if (fp == NULL){ //ä¸åå¨å°±å建åºæ¥è¿ä¸ªæ件fp = fopen(fileName, "w+");}struct bookInfo tempData;while (fscanf(fp, "%s\t%f\t%d\n", tempData.name, &tempData.price, &tempData.num) != EOF){ insertNodeByHead(list, tempData);}fclose(fp);}//å泡æåºï¼é¾è¡¨ï¼void bubbleSortList(struct Node* headNode){ for (struct Node* p = headNode->next; p != NULL; p = p->next){ for (struct Node* q = headNode->next; q->next != NULL; q = q->next){ if (q->data.price > q->next->data.price){ //交æ¢å¼struct bookInfo tempData = q->data;q->data = q->next->data;q->next->data = tempData;}}}printList(headNode);}//2.交äºvoid keyDown(){ int userkey = 0;struct bookInfo tempBook;//产çä¸ä¸ªä¸´æ¶çåéåå¨ä¹¦ç±ä¿¡æ¯struct Node* result = NULL;scanf("%d", &userkey);switch (userkey) { case 0:printf(" ã ç»è®° ã \n");printf("è¾å ¥ä¹¦ç±çä¿¡æ¯(name,price,num):");scanf("%s%f%d", tempBook.name, &tempBook.price, &tempBook.num);insertNodeByHead(list, tempBook);saveInfoToFile("bookinfo.txt", list);break;case 1:printf(" ã æµè§ ã \n");printList(list);break;case 2:printf(" ã åé ã \n"); printf("请è¾å ¥ä½ è¦åé ç书ç±ï¼");scanf("%s", tempBook.name);result = searchByName(list,tempBook.name);if (result == NULL)printf("没æç¸å ³ä¹¦ç±æ æ³åé ï¼\n");else{ if (result->data.num > 0){ result->data.num--;printf("åé æå\n");saveInfoToFile("bookinfo.txt", list);}else{ printf("å½å书ç±æ åºåï¼åé 失败ï¼\n");}}break;case 3:printf(" ã å½è¿ ã \n");printf("请è¾å ¥ä½ è¦å½è¿ç书ç±ï¼");scanf("%s", tempBook.name);result = searchByName(list, tempBook.name);if (result == NULL)printf("书ç±æ¥æºéæ³ï¼\n");else{ result->data.num++;printf("书ç±å½è¿æåï¼\n");saveInfoToFile("bookinfo.txt", list);}break;case 4:printf(" ã æ¥æ¾ ã \n");printf("ä½ è¦æ¥è¯¢ç书åï¼");scanf("%s", tempBook.name);result = searchByName(list, tempBook.name);if (result == NULL){ printf("æªæ¾å°ç¸å ³ç»æ!\n");}else{ printf("书å\tä»·æ ¼\tæ°é\n");printf("%s\t%.1f\t%d\n", result->data.name, result->data.price, result->data.num);}break;case 5:printf(" ã æåº ã \n");bubbleSortList(list);break;case 6:printf(" ã å é¤ ã \n");printf("è¾å ¥æ³è¦å é¤ç书å:");scanf("%s", tempBook.name);deleteNodeByName(list, tempBook.name);saveInfoToFile("bookinfo.txt", list);break;case 7:printf(" ã éåº ã \n");printf(" éåºæå \n");system("pause");exit(0); //å ³ææ´ä¸ªç¨åºbreak;default:printf(" ã error ã \n");break;}}//1.çé¢--->èå--->模åvoid makeMenu(){ printf("----------------------------------\n");printf("Eugeoå¾ä¹¦ç®¡çåé ç³»ç»\n");printf("t0.ç»è®°ä¹¦ç±\n");printf("t1.æµè§ä¹¦ç±\n");printf("t2.åé 书ç±\n");printf("t3.å½è¿ä¹¦ç±\n");printf("t4.æ¥æ¾ä¹¦ç±\n");printf("t5.æåºä¹¦ç±\n");printf("t6.å é¤ä¹¦ç±\n");printf("t7.éåºç³»ç»\n");printf("----------------------------------\n");printf("请è¾å ¥(0~7):");}int main(){ list = createHead();//é¾è¡¨åå§åreadInfoFromFile("bookinfo.txt", list);while (1){ makeMenu();keyDown();system("pause");system("cls");}}åæï¼/post/