473,698 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem analysis

kiemxai
11 New Member
you see that,i did correct or not?
PROBLEM ANALYSIS
For an introduction to program transaction journal, see the background section of assignment .
Not only transaction journal, but also inventory sheet is needed to print at the end of the day. It is the list of items, inventory cost, inventory units, and inventory amount
When items of the same type were purchased at different unit cost, it is the question as to how to calculate the unit cost. There are several methods, here a periodic average cost (PA cost) method is used.
PA cost = Purchase amount /Units puchased (during the period, regardless of the time, at the beginning or at the end of a period )
For example, with the following transactions

Transaction journal

No Transactions Item Unit cost Units purchased Units sold -- ------------- ----- ----------- --------------- -------------
1 Purchase 001 3.0 30
2 Purchase 001 5.0 20
3 Sale 001 30
4 Purchase 002 1.0 20
5 Sale 002 10

Inventory sheet will be as follows

Inventory sheet

Item Description PA cost Inventory units Inventory amount ---- ------------- --------- ----------------- ------------------
001 pen 3.8 20 68
002 pencil 1.0 10 10
-----------------------------------------------------------------
TOTAL 78

PA cost of item 001 = (3.0 * 30 + 5.0 * 20)/(30 + 20) = 190/50 = 3.8, and PA cost of item 002 = 1.0

SPECIFICATIONS
Your transaction journal and inventory sheet program can
• calculate PA cost,
• display an inventory sheet,
• accept and display item descriptions
Your program displays a menu that offers the user five options:
MAIN MENU
--------------------------
1) Enter a Transaction
2) Edit a Transaction by No
3) View Transaction journal
4) View Inventory sheet  NEW
5) Exit
Please select 1, 2, 3, 4, or 5: 1
If 1 is selected, then your program displays the No of transaction and allows the user to enter the transaction detail, including transaction type, item code, item name (only for the first time), unit price (only for puchase transaction), and quantity.
Sample run
Transaction No 1
Enter a transaction type (1 or 2) : 1
Enter a item code : 001
Enter the item name : Pen <= NEW
Enter unit price : -3
**Value must be greater than 0
**Enter again : 3.00
Enter quantity : 10

If the user enters the item code for the first time, your program
• creates the new item code and
• prompts the user to enter a brief description (maximum 30 characters)
Once the user has entered the transaction quantity, your program returns to the main menu
If 2 is selected, the program prompts the user for No of transaction, accepts the No, and displays this transaction details. If transaction No doesn’t exist, the user must be asked to enter again. Then gives the following Edit menu that allows the user to choose which option he/she wants. It allows the user to enter Type of transaction, Item code, Item name, Unit price, or Quantity according with 1, 2, 3, 4, 5 entered. If 6 is entered, it returns to the main menu
Sample run
Enter No of transaction: 10
**Enter again : 1

Type Item code Item name Unit price Quantity
Purchase 001 Pen 3.00 10

Edit Menu
---------
1) Type
2) Item code
3) Item name
4) Unit price
5) Quantity
6) Exit editing
Please select 1, 2, 3, 4, 5, or 6: 5

Enter Quantity : -30
**Value must be greater than 0
**Enter again : 30

Edit Menu
---------
1) Type
2) Item code
3) Item name
4) Unit price
5) Quantity
6) Exit editing
Please select 1, 2, 3, 4, 5, or 6: 6

MAIN MENU
--------------------------
1) Enter a Transaction
2) Edit a Transaction by No
3) View Transaction journal
4) View Inventory sheet
5) Exit
Please select 1, 2, 3, 4, or 5: 3
If 3 is seleted, then program displays all transactions that have been entered, in the order entered. The format of the transaction journal is as follows:

Transaction journal

No Transactions Item Unit cost Units purchased Units sold -- ------------- ----- ----------- --------------- -------------
1 Purchase 001 3.0 30
2 Purchase 001 5.0 20
3 Sale 001 3.8 30
4 Purchase 002 1.0 20
5 Sale 002 1.0 10

Here, the unit cost of the item sold is equal to PA cost.
If 4 is seleted, then program displays inventory sheet. The format of the inventory sheet is as follows:

Inventory sheet

Item Description PA cost Inventory units Inventory amount ---- ------------- --------- ----------------- ------------------
001 Pen 3.8 20 68
002 Pencil 1.0 10 10
-----------------------------------------------------------------
TOTAL 78

Expand|Select|Wrap|Line Numbers
  1. // gr.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #define MAX_ITM 999 //maximum of the item
  12. #define MAX_TRS 20 //maximum of the transaction number
  13. #define MAX 10 //maximum of different items
  14.  
  15. typedef struct trans{
  16.     int tpe; //type
  17.     int itm; //item
  18.     double cst; //cost
  19.     int qtt; //quantity
  20. } transaction; //transaction
  21.  
  22. double input_ctrl(double inf, double sup, int opt);/* get an interger or a number in double type */
  23. int input_chck(double value, double inf, double sup, char ch);/* check if input is valid */
  24.  
  25. void *tst_input(transaction *t, int *n);/* enter the transaction */
  26. int tst_edit(transaction *t, int n); /* allow users editing a transaction by number */
  27. int tst_view(transaction *t, int n, int opt);/* print the transactions to the screen */
  28. int tst_find(transaction *t, int n, int itm);/* find a number through cost item of a transaction */
  29.  
  30. int main() {
  31.     int choice, no = 0;
  32.     transaction *tst;
  33.     /* make a allocation for *tst*/
  34.     tst = (transaction*) malloc( sizeof(transaction));
  35.     do {
  36.         printf("MAIN MENU\n");
  37.         printf("=========\n");
  38.         printf("1) Enter a Transaction.\n");
  39.         printf("2) Edit a Transaction by No.\n");
  40.         printf("3) View Transaction journal.\n");
  41.         printf("4) Exit.\n");
  42.         printf("Please select 1, 2, 3, or 4: ");
  43.         choice = (int) input_ctrl(1, 4, 0);
  44.         switch (choice) {
  45.             case 1:
  46.                 tst = (transaction*) tst_input( tst, &no);
  47.                 break;
  48.             case 2:
  49.                 tst_edit( tst, no);
  50.                 break;
  51.             case 3:
  52.                 tst_view( tst, no, -1);
  53.         }
  54.     } while (choice != 4);
  55.     printf("The application has stopped.");
  56.     getch();
  57.     return 0;
  58. } //end main()
  59.  
  60. double input_ctrl(double inf, double sup, int opt) {
  61.     if ( opt == 0) { //get an integer
  62.         int value, temp;
  63.         char ch;
  64.         do {
  65.             temp = scanf("%d%c", &value, &ch);
  66.             fflush(stdin);
  67.             if (temp == 0)
  68.                 ch = '\0'; //NUL
  69.         } while (!input_chck(value, inf, sup, ch));
  70.         return value;
  71.     } else if (opt == 1){ //get a number type double
  72.         double value, temp;
  73.         char ch;
  74.         do {
  75.             temp = scanf("%lf%c", &value, &ch);
  76.             fflush(stdin);
  77.             if (temp == 0)
  78.                 ch = '\0'; //NUL
  79.         } while (!input_chck(value, inf, sup, ch));
  80.         return value;
  81.     } else return -1;
  82. } //end input_ctrl
  83.  
  84. int input_chck(double value, double inf, double sup, char ch) {
  85.     if (inf < sup) {
  86.         if (ch == '\n') {
  87.             if (value < inf) {
  88.                 printf("  ** Input must be greater than %.0lf . Enter again : ", inf);
  89.                 return 0;
  90.             } else if (value > sup) {
  91.                 printf("  ** Input must be less than %.0lf . Enter again : ", sup);
  92.                 return 0;
  93.             } else
  94.                 return 1;
  95.         } else { //ch != '\n'
  96.             printf("  **Input is invalid. Enter again : ");
  97.             return 0;
  98.         }
  99.     } else if (inf == sup) {
  100.         if (ch == '\n') {
  101.             if (value < inf) {
  102.                 printf("  ** Input must be greater than %.0lf . Enter again : ", inf);
  103.                 return 0;
  104.             } else
  105.                 return 1;
  106.         } else { //ch != '\n'
  107.             printf("  ** Input is invalid. Enter again : ");
  108.             return 0;
  109.         }
  110.     } else //inf > sup
  111.         return -1;
  112. } //end input_chck
  113.  
  114. void *tst_input(transaction *pt, int *n) {
  115.     char ctrl;
  116.     int itm, temp;
  117.     do {
  118.         if ( *n < MAX_TRS) {
  119.             if (*n > 0)
  120.                 pt = (transaction*) realloc ( pt, sizeof(transaction)*(*n+1));
  121.             printf("\nTransaction No %d\n", *n+1);
  122.             printf("Enter a transaction type (1 for Purchase, 2 for Sale)  : ");
  123.             (pt+*n)->tpe = (int) input_ctrl(1, 2, 0);
  124.  
  125.             do {
  126.                 printf("Enter a item code        : ");
  127.                 itm = (int) input_ctrl(1, MAX_ITM, 0);
  128.                 temp = tst_find( pt, *n, itm);
  129.                 if ( temp >= MAX)
  130.                     printf("  ** Error. Cannot enter more than %d of different items.\n",MAX);
  131.             } while ( temp >= MAX);
  132.             (pt+*n)->itm = itm;
  133.  
  134.             if ( (pt+*n)->tpe == 1) {
  135.                 printf("Enter unit cost          : ");
  136.                 (pt+*n)->cst = input_ctrl(0, 0, 1);
  137.             } else  //(t+*n)->.tpe == 2
  138.                 (pt+*n)->cst = 0;
  139.  
  140.             printf("Enter quantity           : ");
  141.             (pt+*n)->qtt = (int) input_ctrl(1, 1, 0);
  142.  
  143.             printf("Press any key to continue (M to go back the menu) ");
  144.             scanf("%c", &ctrl);
  145.             ++*n;
  146.         } else {
  147.             printf("  ** The transaction number cannot be greater %d.\n", MAX_TRS);
  148.             printf("Press any key to continue... ");
  149.             ctrl = 'm';
  150.         }
  151.     } while (ctrl != 'M' && ctrl != 'm');
  152.     printf("\n\n");
  153.     return pt;
  154. } //end trans_input
  155.  
  156. int tst_edit(transaction *pt, int n) {
  157.     int ctrl, itm, tpe, i, temp;
  158.     printf("\nEnter No of transaction: ");
  159.     i = (int) input_ctrl(1, n, 0) - 1;
  160.     tst_view(pt, 0, i);
  161.     do {
  162.         printf("Edit Menu\n");
  163.         printf("---------\n");
  164.         printf("1) Type.\n");
  165.         printf("2) Item code.\n");
  166.         printf("3) Unit cost.\n");
  167.         printf("4) Quantity.\n");
  168.         printf("5) Exit editing.\n");
  169.         printf("Please select 1, 2, 3, 4, or 5: ");
  170.  
  171.         ctrl = (int) input_ctrl(1, 5, 0);
  172.         switch( ctrl) {
  173.             case 1:
  174.                 printf("Enter Type : ");
  175.                 tpe = (int) input_ctrl(1, 2, 0);
  176.                 if ( (pt+i)->tpe == 2 && tpe == 1) {
  177.                     printf("Enter Cost : ");
  178.                     (pt+i)->cst = input_ctrl(0, 0, 1);
  179.                 }
  180.                 (pt+i)->tpe = tpe;
  181.                 break;
  182.             case 2:
  183.                 do {
  184.                     printf("Enter Item Code : ");
  185.                     itm = (int) input_ctrl(1, MAX_ITM, 0);
  186.                     temp = tst_find( pt, n, itm);
  187.                     if ( temp >= MAX)
  188.                         printf("  ** Error. Cannot enter more than %d of different items.\n",MAX);
  189.                 } while ( temp >= MAX);
  190.                 (pt+i)->itm = itm;
  191.                 break;
  192.             case 3:
  193.                 if ( (pt+i)->tpe == 1) {
  194.                     printf("Enter Cost : ");
  195.                     (pt+i)->cst = input_ctrl(0, 0, 1);
  196.                 } else
  197.                     printf("  ** Error. Cannot edit this item.\n");
  198.                 break;
  199.             case 4:
  200.                 printf("Enter Quantity : ");
  201.                 (pt+i)->qtt = (int) input_ctrl(1, 1, 0);
  202.             default:
  203.                 ctrl=0;
  204.         }
  205.         printf("\n");
  206.     } while (ctrl != 0);
  207.     return 0;
  208. } //end trans_edit
  209.  
  210. int tst_view(transaction *pt, int n, int opt) {
  211.     int i;
  212.     if (opt == -1) {
  213.         printf("\n                     Transaction journal                      \n\n");
  214.         printf("No  Transactions  Item  Unit cost  Units purchased  Units sold\n");
  215.         printf("--  ------------  ----  ---------  ---------------  ----------\n");
  216.         for (i = 0; i < n; ++i) {
  217.             if ( (pt+i)->tpe == 1)
  218.                 printf("%2d  Purchase       %03d  %9.1lf  %15d  %10s\n",i+1, (pt+i)->itm, (pt+i)->cst, (pt+i)->qtt," ");
  219.             else //(t+i)->tpe == 2
  220.                 printf("%2d  Sale           %03d  %9s  %15s  %10d\n", i+1, (pt+i)->itm, " ", " ",(pt+i)->qtt);
  221.         }
  222.         printf("Press any key to continue... ");
  223.         getch();
  224.         printf("\n");
  225.     } else { //(opt >= 0)
  226.         if ( (pt+opt)->tpe == 1) {
  227.             printf("Type     Item code      Unit cost      Quantity\n");
  228.             printf("Purchase      %03d      %9.1lf      %8d\n",(pt+opt)->itm, (pt+opt)->cst, (pt+opt)->qtt);
  229.         }
  230.         else { //(t+opt)->tpe == 2
  231.             printf("Type     Item code      Quantity\n");
  232.             printf("Sale          %03d      %8d\n", (pt+opt)->itm, (pt+opt)->qtt);
  233.         }
  234.         printf("\n");
  235.     }
  236.     printf("\n");
  237.     return 0;
  238. } //end trans_view
  239.  
  240. int tst_find(transaction *t, int n, int itm) {
  241.     int i, temp = 0;
  242.     for (i = 0; i < n; ++i) {
  243.         if ( itm != (t+i)->itm)
  244.             ++temp;
  245.     }
  246.     return temp;
  247. } //end tst_find
  248.  
Apr 27 '09 #1
1 2316
RRick
463 Recognized Expert Contributor
You need to be more specific. Is there some problem you have run into?
May 3 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1498
by: Rogue 9 | last post by:
Hi All, I am developing a program called oop_lb.py and it's package structure is as below: oop_lb | -------------------------------------- | | | analysis process tests
16
2657
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects with the same A or B value. But there can be more than one object with A = null or B = null in the bucket. Sometimes there is only one valid solution, sometimes there are more valid solutions, and sometimes there isn't a complete solution at...
117
7205
by: Peter Olcott | last post by:
www.halting-problem.com
0
1565
by: wwalkerbout | last post by:
Greetings, Although, this relates to Analysis Services administration, I thought I'd post it here in case someone with the administrative side of SQL Server who subscribes to this Group may also know Analysis Services and DSO as well. I have a need to run Analysis Services on a single Server instance, but obtaining its data from a SQL Server Cluster. I gather Analysis Services is not designed to work within a SQL Cluster. However, the
2
1641
by: Pawel | last post by:
I have small problem with XslTransformation. I get from WebService xml document. I have xslt and I want transform xml document to html code. It's look easy but I cant't manage with xPath. Maybe someone help me with that. I have problems with xPath in xslt file. I can't navigate by names only by vertical and horizontal axis. What's wrong .... --- Code --- // WebService XmlForAnalysis.Xmla xa = new XmlForAnalysis.Xmla(); xa.Url =...
4
5799
by: Al Norman | last post by:
We have two separate DLLs that do not interact (directly, at least). One is an MFC extension DLL that was built back in VC++ 6 days (but has been recompiled with VS2005). The other is a DLL that contains .Net functions wrapped in C++ (as described by Paul DiLascia -- see http://msdn.microsoft.com/msdnmag/issues/06/06/CAtWork/default.aspx). Both DLLs specify 'Use MFC in a shared DLL'. Since we have an old VC 6 application (large) that we...
5
4484
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of the Main() function: // if this is not the first instance of this application, exit // immediately. Allow only one instance in the system if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
1
1535
by: =?Utf-8?B?TmFkYXYgUG9wcGxld2VsbA==?= | last post by:
Hi everybody, I've got a solution that has several dll projects and a website. For the dll projects I've add a configuration 'debug - no code analysis'. Now for the website I can't create custom configurations... The fact that I can't create different configuration for running with code analysis and without code analysis is irritating, but I could live with it.
0
1446
by: tavares | last post by:
--------------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) Symposium "Computational Methods in Image Analysis" National Congress on Computational Mechanics (USNCCM IX) San Francisco, CA, USA, July 22 - 26 2007 http://www.me.berkeley.edu/compmat/USACM/main.html We would appreciate if you could distribute this information by...
0
1201
by: tavares | last post by:
------------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) Symposium "Computational Methods in Image Analysis" National Congress on Computational Mechanics (USNCCM IX) San Francisco, CA, USA, July 22 - 26 2007 http://www.me.berkeley.edu/compmat/USACM/main.html We would appreciate if you could distribute this information by...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.