- #1
Henry R
- 25
- 0
Good day everyone.
I have some problems here. I need help. This code is my attempt to build a computer program.But, I just found out that I am confuse with my own code.You guys, can check it by your own and please try to fix it.;) Give mesuggestions. If thers's anything wrong then write it to me. There's an image attachment. And, I think I make a lots of mistakes there. I just don't know how to put the right code on right position. Please, tell me the right line of this code. The function,method and arguments. Just tell me . Thank you, so much. And, I also has paste my code here.
Before that, here's the question :
To solve a programming problem by creating a structure which stores information of Computers and to manipulate the structure by using arrays and functions.
A software company has requested you to implement a Computer Information System that will keep up to a maximum of 50 Computer data. The computer’s information to be kept is:
• ComputerID – int
• ComputerName – 50 characters
• ProcessorSpeed – integer
• RAM - Integer
• OperatingSystem – 50 characters
• Price - float
You would need to create a Computer structure and an array called Computers. You are requested to test the Computer Information System developed by performing the tasks b) to e), and display its output.
a)Declare the Computer structure and the Computers array, using the information given above.
b)Insert 5 new computers using a sequential ComputerID
c)Search for a particular computer by ComputerID
d)Search for a particular computer by ComputerName
e)Display a list of all computers Last but not least , this is my program. Not that good right?
View attachment 3537This is my code ...
int SequentialSearch(int list[], int );
/*Computer Information System Programme*/
#include <stdio.h>
#include <string.h>
#include<windows.h>
#include <stdlib.h>
#define N 50
#define TARGET 5
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
/* Name of constructed struct that must fulfill the naming rule of a variable.*/
struct Computers
{
/* DEclaration of local variables */
int i,j;
char ComputerSpecifications [50];
int ComputerID;
char ComputerName [50];
int ProcessorSpeed;
int RAM;
char OperatingSystem [50];
float Price;
};
/* function declaration */
void printComputer( struct Computers computer );
int main(int argc, char *argv[])
{
/*To display or print some brief details of programmer of this program*/
printf("////////////////////////////////////////////////////////////////////////////////\n");
printf("\tProgrammer : Your Name.\n");
printf("\tQuestion No : Question 1.\n\n");
printf("\tTHIS PROGRAM STORES FIVE NEW COMPUTER INFORMATION SYSTEM.\n");
printf("\tIT WILL KEEP UP TO A MAXIMUM 50 COMPUTER DATA.\n");
printf("////////////////////////////////////////////////////////////////////////////////\n");
printf("\tBelow are the specifications of five new computers.\n\n");
struct Computers Computer1; /* Declare Computer1 of type Computer */
struct Computers Computer2; /* Declare Computer2 of type Computer */
struct Computers Computer3; /* Declare Computer3 of type Computer */
struct Computers Computer4; /* Declare Computer4 of type Computer */
struct Computers Computer5; /* Declare Computer5 of type Computer */
/* computer 1 specification */
strcpy( Computer1.ComputerSpecifications, "COMPUTER ONE SPECIFICATIONS");
Computer1.ComputerID = 10111;
strcpy( Computer1.ComputerName, "Asus");
Computer1.ProcessorSpeed = 5;
Computer1.RAM = 8 ;
strcpy( Computer1.OperatingSystem, "Microsoft Windows 8");
Computer1.Price = 2459.00;
/* computer 2 specification */
strcpy( Computer2.ComputerSpecifications, "COMPUTER TWO SPECIFICATIONS");
Computer2.ComputerID = 20222;
strcpy( Computer2.ComputerName, "Apple Macintosh");
Computer2.ProcessorSpeed = 9;
Computer2.RAM = 16 ;
strcpy( Computer2.OperatingSystem, "Apple");
Computer2.Price = 2459.00;
/* computer 3 specification */
strcpy( Computer3.ComputerSpecifications, "COMPUTER THREE SPECIFICATIONS");
Computer3.ComputerID = 30333;
strcpy( Computer3.ComputerName, "Lenovo");
Computer3.ProcessorSpeed = 9;
Computer3.RAM = 4 ;
strcpy( Computer3.OperatingSystem, "Microsoft Windows 7");
Computer3.Price = 1459.00;
/* computer 4 specification */
strcpy( Computer4.ComputerSpecifications, "COMPUTER FOUR SPECIFICATIONS");
Computer4.ComputerID = 40444;
strcpy( Computer4.ComputerName, "Dell");
Computer4.ProcessorSpeed = 9;
Computer4.RAM = 8 ;
strcpy( Computer4.OperatingSystem, "Linux Ubuntu");
Computer4.Price = 1600.00;
/* computer 5 specification */
strcpy( Computer5.ComputerSpecifications, "COMPUTER FIVE SPECIFICATIONS");
Computer5.ComputerID = 50555;
strcpy( Computer5.ComputerName, "Alienware");
Computer5.ProcessorSpeed = 20;
Computer5.RAM = 24 ;
strcpy( Computer5.OperatingSystem, "Android");
Computer5.Price = 5500.00;
/* print Computer1 info */
printComputer( Computer1 );
/* print Computer2 info */
printComputer( Computer2 );
/* print computer3 info */
printComputer( Computer3 );
/* print computer4 info */
printComputer( Computer4 );
/*print computer5 info */
printComputer( Computer5 );
return 0;
}/* Function declarations */
void printComputer( struct Computers computer )
{
printf( "\n\t%s\n", computer.ComputerSpecifications);
printf( "\n\tComputer ID\t :%d\n", computer.ComputerID);
printf( "\tComputer Name :%s\n", computer.ComputerName);
printf( "\tProcessor Speed :CPU %dGhz\n", computer.ProcessorSpeed);
printf( "\tInstalled Memory (RAM) :%d.00 GB\n", computer.RAM);
printf( "\tOperating System Type :%s\n", computer.OperatingSystem);
printf( "\tPrice (RM) :%.2f\n\n\n",computer.Price);
/* Declaration of local variables */
int i, data [12];
int ComputerID, found;
/*Enter data into an array of size 50*/
for (i = 0; i < TARGET ; i++)
{
printf("Enter computer data %d:", (i+1));
scanf ("\n%d", &data);
}
/* Search operation */
printf("What computer do you want to search? : ");
scanf("%d", &ComputerID);
found = SequentialSearch (data,ComputerID);
if (found != -1 )
printf("Found computer at the %d\n ", ComputerID, found);
else
printf("Data not found");
}
/*Function to search list */
int SequentialSearch (int list[], int SearchData)
{
int location = -1;
int indx;
for (indx = 0; indx <= TARGET; indx++){
if (SearchData == list[indx])
location = indx;
}
return location;
system("PAUSE");
return 0;
}
I have some problems here. I need help. This code is my attempt to build a computer program.But, I just found out that I am confuse with my own code.You guys, can check it by your own and please try to fix it.;) Give mesuggestions. If thers's anything wrong then write it to me. There's an image attachment. And, I think I make a lots of mistakes there. I just don't know how to put the right code on right position. Please, tell me the right line of this code. The function,method and arguments. Just tell me . Thank you, so much. And, I also has paste my code here.
Before that, here's the question :
To solve a programming problem by creating a structure which stores information of Computers and to manipulate the structure by using arrays and functions.
A software company has requested you to implement a Computer Information System that will keep up to a maximum of 50 Computer data. The computer’s information to be kept is:
• ComputerID – int
• ComputerName – 50 characters
• ProcessorSpeed – integer
• RAM - Integer
• OperatingSystem – 50 characters
• Price - float
You would need to create a Computer structure and an array called Computers. You are requested to test the Computer Information System developed by performing the tasks b) to e), and display its output.
a)Declare the Computer structure and the Computers array, using the information given above.
b)Insert 5 new computers using a sequential ComputerID
c)Search for a particular computer by ComputerID
d)Search for a particular computer by ComputerName
e)Display a list of all computers Last but not least , this is my program. Not that good right?
View attachment 3537This is my code ...
int SequentialSearch(int list[], int );
/*Computer Information System Programme*/
#include <stdio.h>
#include <string.h>
#include<windows.h>
#include <stdlib.h>
#define N 50
#define TARGET 5
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
/* Name of constructed struct that must fulfill the naming rule of a variable.*/
struct Computers
{
/* DEclaration of local variables */
int i,j;
char ComputerSpecifications [50];
int ComputerID;
char ComputerName [50];
int ProcessorSpeed;
int RAM;
char OperatingSystem [50];
float Price;
};
/* function declaration */
void printComputer( struct Computers computer );
int main(int argc, char *argv[])
{
/*To display or print some brief details of programmer of this program*/
printf("////////////////////////////////////////////////////////////////////////////////\n");
printf("\tProgrammer : Your Name.\n");
printf("\tQuestion No : Question 1.\n\n");
printf("\tTHIS PROGRAM STORES FIVE NEW COMPUTER INFORMATION SYSTEM.\n");
printf("\tIT WILL KEEP UP TO A MAXIMUM 50 COMPUTER DATA.\n");
printf("////////////////////////////////////////////////////////////////////////////////\n");
printf("\tBelow are the specifications of five new computers.\n\n");
struct Computers Computer1; /* Declare Computer1 of type Computer */
struct Computers Computer2; /* Declare Computer2 of type Computer */
struct Computers Computer3; /* Declare Computer3 of type Computer */
struct Computers Computer4; /* Declare Computer4 of type Computer */
struct Computers Computer5; /* Declare Computer5 of type Computer */
/* computer 1 specification */
strcpy( Computer1.ComputerSpecifications, "COMPUTER ONE SPECIFICATIONS");
Computer1.ComputerID = 10111;
strcpy( Computer1.ComputerName, "Asus");
Computer1.ProcessorSpeed = 5;
Computer1.RAM = 8 ;
strcpy( Computer1.OperatingSystem, "Microsoft Windows 8");
Computer1.Price = 2459.00;
/* computer 2 specification */
strcpy( Computer2.ComputerSpecifications, "COMPUTER TWO SPECIFICATIONS");
Computer2.ComputerID = 20222;
strcpy( Computer2.ComputerName, "Apple Macintosh");
Computer2.ProcessorSpeed = 9;
Computer2.RAM = 16 ;
strcpy( Computer2.OperatingSystem, "Apple");
Computer2.Price = 2459.00;
/* computer 3 specification */
strcpy( Computer3.ComputerSpecifications, "COMPUTER THREE SPECIFICATIONS");
Computer3.ComputerID = 30333;
strcpy( Computer3.ComputerName, "Lenovo");
Computer3.ProcessorSpeed = 9;
Computer3.RAM = 4 ;
strcpy( Computer3.OperatingSystem, "Microsoft Windows 7");
Computer3.Price = 1459.00;
/* computer 4 specification */
strcpy( Computer4.ComputerSpecifications, "COMPUTER FOUR SPECIFICATIONS");
Computer4.ComputerID = 40444;
strcpy( Computer4.ComputerName, "Dell");
Computer4.ProcessorSpeed = 9;
Computer4.RAM = 8 ;
strcpy( Computer4.OperatingSystem, "Linux Ubuntu");
Computer4.Price = 1600.00;
/* computer 5 specification */
strcpy( Computer5.ComputerSpecifications, "COMPUTER FIVE SPECIFICATIONS");
Computer5.ComputerID = 50555;
strcpy( Computer5.ComputerName, "Alienware");
Computer5.ProcessorSpeed = 20;
Computer5.RAM = 24 ;
strcpy( Computer5.OperatingSystem, "Android");
Computer5.Price = 5500.00;
/* print Computer1 info */
printComputer( Computer1 );
/* print Computer2 info */
printComputer( Computer2 );
/* print computer3 info */
printComputer( Computer3 );
/* print computer4 info */
printComputer( Computer4 );
/*print computer5 info */
printComputer( Computer5 );
return 0;
}/* Function declarations */
void printComputer( struct Computers computer )
{
printf( "\n\t%s\n", computer.ComputerSpecifications);
printf( "\n\tComputer ID\t :%d\n", computer.ComputerID);
printf( "\tComputer Name :%s\n", computer.ComputerName);
printf( "\tProcessor Speed :CPU %dGhz\n", computer.ProcessorSpeed);
printf( "\tInstalled Memory (RAM) :%d.00 GB\n", computer.RAM);
printf( "\tOperating System Type :%s\n", computer.OperatingSystem);
printf( "\tPrice (RM) :%.2f\n\n\n",computer.Price);
/* Declaration of local variables */
int i, data [12];
int ComputerID, found;
/*Enter data into an array of size 50*/
for (i = 0; i < TARGET ; i++)
{
printf("Enter computer data %d:", (i+1));
scanf ("\n%d", &data);
}
/* Search operation */
printf("What computer do you want to search? : ");
scanf("%d", &ComputerID);
found = SequentialSearch (data,ComputerID);
if (found != -1 )
printf("Found computer at the %d\n ", ComputerID, found);
else
printf("Data not found");
}
/*Function to search list */
int SequentialSearch (int list[], int SearchData)
{
int location = -1;
int indx;
for (indx = 0; indx <= TARGET; indx++){
if (SearchData == list[indx])
location = indx;
}
return location;
system("PAUSE");
return 0;
}
Attachments
Last edited: