Skip to main content

CROP STRUCTURE Crop structure Jack is an application software developer recently he has been assigned to a new project for crop management by the government. Actually, his task is to develop an app which will maintain the crop details like required rainfall, the temperature suitable for the growth of the plant, sow date, and harvest date. The Government would need to plan the budget for crops during the start of the financial year, for which required water quantity, pesticide, infrastructure to maintain temperature all are factors that affect harvest date of a crop. So help Jack in building filters by temperature and rainfall and sort the crops by sow date, harvest date. This will help the government to plan budget according to the sow and harvest date. Create a structure called Date. struct Date{ int dd; int mm; int yyyy; }; Create a structure called Crop. struct Crop{ char name[30]; float rainfall; int temperature; Date sowDate; Date harvestDate; }; Get the details from the user. Assume that no two details are same. Menu: 1) Crop that needs the highest rainfall 2) Crop that needs the highest temperature 3) Display the crop sorted in ascending order of the sowDate 4) Display the crop sorted in ascending order of the harvestDate Input and Output Format: Refer sample input and output for formatting specifications. All float values are displayed correctly to 2 decimal places. All text in bold corresponds to the input and the rest corresponds to output. Sample Input And Output: Enter the number of Crops 2 Enter the details of Crops 1 Enter name Rice Enter rainfall 15 Enter temperature 23 Enter sowDate 25 7 2016 Enter harvestDate 30 11 2016 Enter the details of Crops 2 Enter name Wheat Enter rainfall 7 Enter temperature 29 Enter sowDate 24 7 2016 Enter harvestDate 31 11 2016 Menu 1)Crop that needs the highest rainfall 2)Crop that needs the highest temperature 3)Display the crop sorted in ascending order of the sowDate 4)Display the crop sorted in ascending order of the harvestDate Enter your Choice 1 Crop that needs the highest rain fall is Rice Menu 1)Crop that needs the highest rainfall 2)Crop that needs the highest temperature 3)Display the crop sorted in ascending order of the sowDate 4)Display the crop sorted in ascending order of the harvestDate Enter your Choice 2 Crop that needs the highest temperature is Wheat Menu 1)Crop that needs the highest rainfall 2)Crop that needs the highest temperature 3)Display the crop sorted in ascending order of the sowDate 4)Display the crop sorted in ascending order of the harvestDate Enter your Choice 3 Wheat 7.00 29 24 7 2016 31 11 2016 Rice 15.00 23 25 7 2016 30 11 2016 Menu 1)Crop that needs the highest rainfall 2)Crop that needs the highest temperature 3)Display the crop sorted in ascending order of the sowDate 4)Display the crop sorted in ascending order of the harvestDate Enter your Choice 4 Rice 15.00 23 25 7 2016 30 11 2016 Wheat 7.00 29 24 7 2016 31 11 2016 Menu 1)Crop that needs the highest rainfall 2)Crop that needs the highest temperature 3)Display the crop sorted in ascending order of the sowDate 4)Display the crop sorted in ascending order of the harvestDate Enter your Choice 5 EXIT #include #include #include struct Crop { char name[30]; float rainfall; int temperature; struct Date { int dd; int mm; int yyyy; }sowDate,harvestDate; }c[30]; int n,ch,i,j,temp,sdtemp,smtemp,sytemp,hdtemp,hmtemp,hytemp; float ftemp; char ctemp[40]; int main() { printf("Enter the number of Crops\n"); scanf("%d",&n); for(i=1;i<=n;i++) { printf("Enter the details of Crops %d\n",i); printf("Enter name\n"); scanf("%s",c[i].name); printf("Enter rainfall\n"); scanf("%f",&c[i].rainfall); printf("Enter temperature\n"); scanf("%d",&c[i].temperature); printf("Enter sowDate\n"); scanf("%d%d%d",&c[i].sowDate.dd,&c[i].sowDate.mm,&c[i].sowDate.yyyy); printf("Enter harvestDate\n"); scanf("%d%d%d",&c[i].harvestDate.dd,&c[i].harvestDate.mm,&c[i].harvestDate.yyyy); } while(1) { printf("Menu"); printf("\n1)Crop that needs the highest rainfall\n"); printf("2)Crop that needs the highest temperature\n"); printf("3)Display the crop sorted in ascending order of the sowDate\n"); printf("4)Display the crop sorted in ascending order of the harvestDate\n"); printf("Enter your Choice\n"); scanf("%d",&ch); switch(ch) { case 1: {for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(c[i].rainfall > c[j].rainfall) { ftemp=c[j].rainfall; c[j].rainfall=c[i].rainfall; c[i].rainfall=ftemp; strcpy(ctemp,c[j].name); strcpy(c[j].name,c[i].name); strcpy(c[i].name,ctemp); temp=c[i].temperature; c[i].temperature=c[j].temperature; c[j].temperature=temp; sdtemp=c[i].sowDate.dd; c[i].sowDate.dd=c[j].sowDate.dd; c[j].sowDate.dd=sdtemp; smtemp=c[i].sowDate.mm; c[i].sowDate.mm=c[j].sowDate.mm; c[j].sowDate.mm=smtemp; sytemp=c[i].sowDate.yyyy; c[i].sowDate.yyyy=c[j].sowDate.yyyy; c[j].sowDate.yyyy=sytemp; hdtemp=c[i].harvestDate.dd; c[i].harvestDate.dd=c[j].harvestDate.dd; c[j].harvestDate.dd=hdtemp; hmtemp=c[i].harvestDate.mm; c[i].harvestDate.mm=c[j].harvestDate.mm; c[j].harvestDate.mm=hmtemp; hytemp=c[i].harvestDate.yyyy; c[i].harvestDate.yyyy=c[j].harvestDate.yyyy; c[j].harvestDate.yyyy=hytemp; } } } printf("Crop that needs the highest rain fall is %s",c[n].name);} break; case 2: for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(c[i].temperature > c[j].temperature) { temp=c[j].temperature; c[j].temperature=c[i].temperature; c[i].temperature=temp; strcpy(ctemp,c[j].name); strcpy(c[j].name,c[i].name); strcpy(c[i].name,ctemp); ftemp=c[i].rainfall; c[i].rainfall=c[j].rainfall; c[j].rainfall=ftemp; sdtemp=c[i].sowDate.dd; c[i].sowDate.dd=c[j].sowDate.dd; c[j].sowDate.dd=sdtemp; smtemp=c[i].sowDate.mm; c[i].sowDate.mm=c[j].sowDate.mm; c[j].sowDate.mm=smtemp; sytemp=c[i].sowDate.yyyy; c[i].sowDate.yyyy=c[j].sowDate.yyyy; c[j].sowDate.yyyy=sytemp; hdtemp=c[i].harvestDate.dd; c[i].harvestDate.dd=c[j].harvestDate.dd; c[j].harvestDate.dd=hdtemp; hmtemp=c[i].harvestDate.mm; c[i].harvestDate.mm=c[j].harvestDate.mm; c[j].harvestDate.mm=hmtemp; hytemp=c[i].harvestDate.yyyy; c[i].harvestDate.yyyy=c[j].harvestDate.yyyy; c[j].harvestDate.yyyy=hytemp; } } } printf("Crop that needs the highest temperature is %s",c[n].name); break; case 3: for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if((c[i].sowDate.dd > c[j].sowDate.dd)||(c[i].sowDate.mm > c[j].sowDate.mm)||(c[i].sowDate.yyyy > c[j].sowDate.yyyy)) { strcpy(ctemp,c[i].name); strcpy(c[i].name,c[j].name); strcpy(c[j].name,ctemp); ftemp=c[i].rainfall; c[i].rainfall=c[j].rainfall; c[j].rainfall=ftemp; temp=c[i].temperature; c[i].temperature=c[j].temperature; c[j].temperature=temp; sdtemp=c[i].sowDate.dd; c[i].sowDate.dd=c[j].sowDate.dd; c[j].sowDate.dd=sdtemp; smtemp=c[i].sowDate.mm; c[i].sowDate.mm=c[j].sowDate.mm; c[j].sowDate.mm=smtemp; sytemp=c[i].sowDate.yyyy; c[i].sowDate.yyyy=c[j].sowDate.yyyy; c[j].sowDate.yyyy=sytemp; hdtemp=c[i].harvestDate.dd; c[i].harvestDate.dd=c[j].harvestDate.dd; c[j].harvestDate.dd=hdtemp; hmtemp=c[i].harvestDate.mm; c[i].harvestDate.mm=c[j].harvestDate.mm; c[j].harvestDate.mm=hmtemp; hytemp=c[i].harvestDate.yyyy; c[i].harvestDate.yyyy=c[j].harvestDate.yyyy; c[j].harvestDate.yyyy=hytemp; } } } for(i=1;i<=n;i++) { printf("%s\n",c[i].name); printf("%0.2f\n",c[i].rainfall); printf("%d\n",c[i].temperature); printf("%d %d %d\n",c[i].sowDate.dd,c[i].sowDate.mm,c[i].sowDate.yyyy); printf("%d %d %d\n",c[i].harvestDate.dd,c[i].harvestDate.mm,c[i].harvestDate.yyyy); } break; case 4: for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if((c[i].harvestDate.dd > c[j].harvestDate.dd)||(c[i].harvestDate.mm > c[j].harvestDate.mm)||(c[i].harvestDate.yyyy > c[j].harvestDate.yyyy)) { strcpy(ctemp,c[i].name); strcpy(c[i].name,c[j].name); strcpy(c[j].name,ctemp); ftemp=c[i].rainfall; c[i].rainfall=c[j].rainfall; c[j].rainfall=ftemp; temp=c[i].temperature; c[i].temperature=c[j].temperature; c[j].temperature=temp; sdtemp=c[i].sowDate.dd; c[i].sowDate.dd=c[j].sowDate.dd; c[j].sowDate.dd=sdtemp; smtemp=c[i].sowDate.mm; c[i].sowDate.mm=c[j].sowDate.mm; c[j].sowDate.mm=smtemp; sytemp=c[i].sowDate.yyyy; c[i].sowDate.yyyy=c[j].sowDate.yyyy; c[j].sowDate.yyyy=sytemp; hdtemp=c[i].harvestDate.dd; c[i].harvestDate.dd=c[j].harvestDate.dd; c[j].harvestDate.dd=hdtemp; hmtemp=c[i].harvestDate.mm; c[i].harvestDate.mm=c[j].harvestDate.mm; c[j].harvestDate.mm=hmtemp; hytemp=c[i].harvestDate.yyyy; c[i].harvestDate.yyyy=c[j].harvestDate.yyyy; c[j].harvestDate.yyyy=hytemp; } } } for(i=1;i<=n;i++) { printf("%s\n",c[i].name); printf("%0.2f\n",c[i].rainfall); printf("%d\n",c[i].temperature); printf("%d %d %d\n",c[i].sowDate.dd,c[i].sowDate.mm,c[i].sowDate.yyyy); printf("%d %d %d\n",c[i].harvestDate.dd,c[i].harvestDate.mm,c[i].harvestDate.yyyy); } break; default: printf("EXIT\n"); exit(0); } } return 0; }

Comments

Popular posts from this blog

C Program To Calculate The Revenue The demand for organic food increases every year by 8.9%. Write a program to find the increase in revenue after 3 years. Given the revenue in the first year is ‘x’ crores. Input Format: The first line of the input is an integer that corresponds to the ‘x’ value. Output Format: Output is a float value that corresponds to the revenue after 3 years, rounded off to 2 decimal places. Sample Input: 4 Sample Output: 5.17 //PROGRAM #include<stdio.h> int main() {     int x,i;     float rev;     scanf("%d",&x);     rev=x;     for(i=0;i<3;i++)     {         rev=rev*(1.089);     } printf("%.2f",rev); return 0; }
CROP DETAILS Crop Details A small farmer, Mr.John, use to grow different crops every year in his field. All the crops are being grown using goat manure, farmyard manure, groundnut and neem cake. All the crops are grown organically. He got high yield by using sufficient water and fertilizers at in this year. He will sell his crops in the market. In the market, he wants to maintain the details of each crop that are purchased by customers. Details like crop name, the weight of the crop, cost of the crop Display the details of crops in ascending order of crop names. Create a structure called crop. struct crop{ char cropName[30]; float weight; int cost; }; Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correctly to 2 decimal places. All text in bold corresponds to the input and the rest corresponds to output. Sample Input and Output: Enter the number of Crops 2 Enter the details of Crop 1 Enter name...
STRUCTURE:BUILDING Structures : Building Create a structure called Building. struct Building { char name[100]; float length; float width; float height; float ratePerSqFt; }; Write a program to get the details of 'n' buildings and to display the name, area and rate for painting the inner side of the building per square feet of each building, sorted by name in ascending order. Length, width and height of the building are given in feet. The flooring is also done with the same rate. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output: Enter the number of buildings 2 Enter the details of building 1 Enter name Vikram Enter length 200 Enter width 150 Enter height 10 Enter rate per square feet 650.5 Enter the details of building 2 Enter name Ganesh Enter length 1...