Computer Information System Program

Click For Summary

Discussion Overview

The discussion revolves around a programming problem related to creating a Computer Information System using structures, arrays, and functions in C. Participants are examining a code snippet provided by the original poster, who is seeking assistance in debugging and improving their implementation.

Discussion Character

  • Technical explanation
  • Homework-related
  • Exploratory

Main Points Raised

  • The original poster expresses confusion about their code and requests specific suggestions for corrections, particularly regarding the structure and organization of the code.
  • Participants are asked to review the provided code, which includes a structure for storing computer information and various functions for manipulating that data.
  • The original poster outlines the requirements for the Computer Information System, including the need to store data for up to 50 computers and perform tasks such as inserting new computers and searching by ComputerID and ComputerName.
  • Some participants may propose different approaches to structuring the code or suggest best practices for organizing the functions and data handling.
  • There is an indication that the original poster has pasted their code but has not received feedback yet, leaving room for further discussion and exploration of potential solutions.

Areas of Agreement / Disagreement

The discussion is currently unresolved, with no consensus reached on the specific issues within the code or the best approaches to take. Participants have yet to provide feedback or corrections.

Contextual Notes

The original poster's code includes several functions and structures, but there are indications of potential errors or misplacements in the code logic that have not been explicitly identified or corrected by participants yet.

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: 170
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K