MHB Computer Information System Program

AI Thread Summary
A user is seeking assistance with their code for a Computer Information System program designed to manage data for up to 50 computers. The program requires creating a structure to store various attributes such as ComputerID, ComputerName, ProcessorSpeed, RAM, OperatingSystem, and Price. The user expresses confusion over the code's organization and requests specific guidance on correcting mistakes related to function placement and argument usage. Key tasks include declaring the Computer structure, inserting new computer data, and implementing search functionality. The user has provided their code for review and is looking for suggestions to improve it.
Henry R
Messages
25
Reaction score
0
Good day everyone.

I have some problems here. I need help.:confused: 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

  • Question 1.PNG
    Question 1.PNG
    13.1 KB · Views: 147
Last edited:
Technology news on Phys.org
Henry R said:
Good day everyone.

I have some problems here. I need help.:confused: 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;
}


Hi Henry R!

Your problem statement says: "You would need to create a Computer structure and an array called Computers."

Currently you have a structure named [m]Computers[/m] that actually contains the information about 1 computer.
So I suggest you change the name to [m]Computer[/m], which would satisfy the first part of the sentence.

You still have to create an array called "Computers".
How would an array be declared? (Wondering)

Furthermore, you have a function:
Code:
int SequentialSearch (int list[], int SearchData)
This function is supposed to search in an array for specific data.
However, for this problem your array (named "list") does not contain integers, but [m]Computer[/m]'s, so perhaps you can change the type [m]int[/m] to [m]Computer[/m] and adjust the function to search for a "ComputerId" in that array? (Wondering)
 
I like Serena said:
Hi Henry R!

Your problem statement says: "You would need to create a Computer structure and an array called Computers."

Currently you have a structure named [m]Computers[/m] that actually contains the information about 1 computer.
So I suggest you change the name to [m]Computer[/m], which would satisfy the first part of the sentence.

You still have to create an array called "Computers".
How would an array be declared? (Wondering)

Furthermore, you have a function:
Code:
int SequentialSearch (int list[], int SearchData)
This function is supposed to search in an array for specific data.
However, for this problem your array (named "list") does not contain integers, but [m]Computer[/m]'s, so perhaps you can change the type [m]int[/m] to [m]Computer[/m] and adjust the function to search for a "ComputerId" in that array? (Wondering)
Thank you... I just try my best.
 
I like Serena said:
Hi Henry R!

Your problem statement says: "You would need to create a Computer structure and an array called Computers."

Currently you have a structure named [m]Computers[/m] that actually contains the information about 1 computer.
So I suggest you change the name to [m]Computer[/m], which would satisfy the first part of the sentence.

You still have to create an array called "Computers".
How would an array be declared? (Wondering)

Furthermore, you have a function:
Code:
int SequentialSearch (int list[], int SearchData)
This function is supposed to search in an array for specific data.
However, for this problem your array (named "list") does not contain integers, but [m]Computer[/m]'s, so perhaps you can change the type [m]int[/m] to [m]Computer[/m] and adjust the function to search for a "ComputerId" in that array? (Wondering)
Can you give website links that I can refer to? Just that. Thanks for helping. I've been searching for good examples. But, I got none of them.
 
Henry R said:
Can you give website links that I can refer to? Just that. Thanks for helping. I've been searching for good examples. But, I got none of them.

What kind of website link are you looking for?
 
I like Serena said:
What kind of website link are you looking for?

Website of C programming language that stores computer data records. Please,please, please...:o There's a lot of website but, you know I couldn't find them.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top