-->

Moniac computer

Introduction:- 

The MONIAC (Monetary National Income Analogue Computer) also known as the Phillips Hydraulic Computer and the Financephalograph, was created in 1949 by the New Zealand economist Bill Phillips (William Phillips) to model the national economic processes of the United Kingdom, while Phillips was a student at the London School of Economics (LSE). The MONIAC was an analogue computer which used fluidic logic to model the workings of an economy. The MONIAC name may have been suggested by an association of money and ENIAC, an early electronic digital computer.

Design and uses:-

The MONIAC was approximately 2 m high, 1.2 m wide and almost 1 m deep, and consisted of a series of transparent plastic tanks and pipes which were fastened to a wooden board. Each tank represented some aspect of the UK national economy and the flow of money around the economy was illustrated by coloured water. At the top of the board was a large tank called the treasury. Water (representing money) flowed from the treasury to other tanks representing the various ways in which a country could spend its money. For example, there were tanks for health and education. To increase spending on health care a tap could be opened to drain water from the treasury to the tank which represented health spending. Water then ran further down the model to other tanks, representing other interactions in the economy. Water could be pumped back to the treasury from some of the tanks to represent taxation. Changes in tax rates were modeled by increasing or decreasing pumping speeds.

Savings reduce the funds available to consumers and investment income increases those funds. The MONIAC showed it by draining water (savings) from the expenditure stream and by injecting water (investment income) into that stream. When the savings flow exceeds the investment flow, the level of water in the savings and investment tank (the surplus-balances tank) would rise to reflect the accumulated balance. When the investment flow exceeds the savings flow for any length of time, the surplus-balances tank would run dry. Import and export were represented by water draining from the model and by additional water being poured into the model.

The actual flow of the water was automatically controlled through a series of floats, counterweights, electrodes, and cords. When the level of water reached a certain level in a tank, pumps and drains would be activated. To their surprise, Phillips and his associate Walter Newlyn found that MONIAC could be calibrated to an accuracy of 2%.

The flow of water between the tanks was determined by economic principles and the settings for various parameters. Different economic parameters, such as tax rates and investment rates, could be entered by setting the valves which controlled the flow of water about the computer. Users could experiment with different settings and note the effect on the model. The MONIAC’s ability to model the subtle interaction of a number of variables made it a powerful tool for its time. When a set of parameters resulted in a viable economy the model would stabilise and the results could be read from scales. The output from the computer could also be sent to a rudimentary plotter.

MONIAC had been designed to be used as a teaching aid but was discovered also to be an effective economic simulator. At the time that MONIAC was created, electronic digital computers that could run complex economic simulations were unavailable. In 1949, the few computers in existence were restricted to government and military use. Neither did they have adequate visual display facilities, so were unable to illustrate the operation of complex models. Observing the MONIAC in operation made it much easier for students to understand the interrelated processes of a national economy. The range of organisations that acquired a MONIAC showed that it was used in both capacities.

Phillips scrounged a variety of materials to create his prototype computer, including bits and pieces from war surplus such as parts from old Lancaster bombers. The first MONIAC was created in his landlady’s garage in Croydon at a cost of £400 (equivalent to £14,000 in 2019).

Phillips first demonstrated the MONIAC to a number of leading economists at the LSE in 1949. It was very well received and Phillips was soon offered a teaching position at the LSE.

                                                                                                source:wikipedia.org

Curta

 The Curta is a small mechanical calculator developed by Curt Herzstark. The Curta's design is a descendant of Gottfried Leibniz's Stepped Reckoner and Charles Thomas's Arithmometer, accumulating values on cogs, which are added or complemented by a stepped drum mechanism. It has an extremely compact design: a small cylinder that fits in the palm of the hand.

Curtas were considered the best portable calculators available until they were displaced by electronic calculators in the 1970s.

Design

Numbers are entered using slides (one slide per digit) on the side of the device. The revolution counter and result counter reside around the shiftable carriage, at the top of the machine. A single turn of the crank adds the input number to the result counter, at any carriage position, and increments the corresponding digit of the revolution counter. Pulling the crank upwards slightly before turning performs a subtraction instead of an addition. Multiplication, division, and other functions require a series of crank and carriage-shifting operations.

The Curta was affectionately known as the "pepper grinder" or "peppermill" due to its shape and means of operation. It was also termed the "math grenade" due to its superficial resemblance to a certain type of hand grenade.

                                                                                                                source:wikipedia.org

Z1 computer

 The Z1 was a motor-driven mechanical computer designed by Konrad Zuse from 1936 to 1937, which he built in his parents' home from 1936 to 1938. It was a binary electrically driven mechanical calculator with limited programmability, reading instructions from punched celluloid film.

The “Z1” was the first freely programmable computer in the world which used Boolean logic and binary floating-point numbers, however it was unreliable in operation. It was completed in 1938 and financed completely from private funds. This computer was destroyed in the bombardment of Berlin in December 1943, during World War II, together with all construction plans.

The Z1 was the first in a series of computers that Zuse designed. Its original name was "V1" for VersuchsModell 1 (meaning Experimental Model 1). After WW2, it was renamed "Z1" to differentiate from the flying bombs designed by Robert Lusser. The Z2 and Z3 were follow-ups based on many of the same ideas as the Z1.

Construction:-

"Z1 was a machine of about 1000 kg weight, which consisted of some 20,000 parts. It was a programmable computer, based on binary floating-point numbers and a binary switching system. It consisted completely of thin metal sheets, which Zuse and his friends produced using a jigsaw." "The [data] input device was a keyboard...The Z1’s programs (Zuse called them Rechenpläne, computing plans) were stored on punch tapes by means of an 8-bit code"

Construction of the Z1 was privately financed. Zuse got money from his parents, his sister Lieselotte, some students of the fraternity AV Motiv (cf. Helmut Schreyer) and Kurt Pannke (a calculating machine manufacturer in Berlin) to do so.

Zuse constructed the Z1 in his parent's apartment; in fact, he was allowed to use the living room for his construction. In 1936, Zuse quit his job in airplane construction in order to build the Z1.

Zuse is said to have used "thin metal strips" and perhaps "metal cylinders" or glass plates to construct Z1. There were probably no commercial relays in it (though the Z3 is said to have used a few telephone relays). The only electrical unit was an electric motor to give the clock frequency of 1 Hz (cycle per second) to the machine.

'The memory was constructed from thin strips of slotted metal and small pins, and proved faster, smaller, and more reliable, than relays. The Z2 used the mechanical memory of the Z1, but used relay-based arithmetic. The Z3 was experimentally built entirely of relays. The Z4 was the first attempt at a commercial computer, reverting to the faster and more economical mechanical slotted metal strip memory, with relay processing, of the Z2, but the war interrupted the Z4 development.'

The Z1 was never very reliable in operation because of poor synchronization caused by internal and external stresses on the mechanical parts.

                                                                                         source:wikipedia.org

Kerrison Predictor

 The Kerrison Predictor was one of the first fully automated anti-aircraft fire-control systems. The predictor could aim a gun at an aircraft based on simple inputs like the observed speed and the angle to the target. Such devices had been used on ships for gunnery control for some time, and versions such as the Vickers Predictor were available for larger anti-aircraft guns intended to be used against high-altitude bombers, but the Kerrison's electromechanical analog computer was the first to be fast enough to be used in the demanding high-speed low-altitude role, which involved very short engagement times and high angular rates.

                    The Kerrison Predictor was a relatively simple device compared to high-altitude predictors and was designed to meet these particular requirements. It was designed by Major A.V. Kerrison at the Admiralty Research Laboratory, Teddington, in the late 1930s. After the war, Kerrison went on to become Director of Aeronautical and Engineering Research at the British Admiralty.

The Predictor solved the problem by doing all of the calculations mechanically through a complex system of gears. Inputs to its calculations included wind speed, ballistics of the gun and the rounds it fired, angle to the target in azimuth and altitude, and a user-input estimated target speed. Some of these inputs were fed in by dials, which turned gearing inside the Predictor to calculate the range (from the change in angle and estimated speed) and direction of motion. The "output" of the device drove hydraulic servo-motors attached to the traversal and elevation gears of the otherwise unmodified Bofors gun, allowing it to follow the predictor's indications automatically without manual intervention. The gunners simply kept the gun loaded, while the three aimers simply had to point the Predictor, mounted on a large tripod, at the target. The Kerrison predictor did not calculate fuse settings, as the shells fired by the 40 mm Bofors gun, with which it was designed to work, were contact-fused.

The Predictor proved to be able to hit practically anything that flew in a straight line, and it was particularly effective against dive bombers. However, it was also very complex, including over 1,000 precision parts and weighing over 500 lb (230 kg), even though much of it was made of aluminium to reduce weight. With the demands of the RAF for almost all light metals and machinists, the Predictor was far too difficult for the Army to produce in any quantity.

While the Predictor proved to be an excellent addition to the Bofors, it was not without its faults. The main problem was that the system required a fairly large electrical generator in order to drive the gun, increasing the logistics load in supplying the generators with fuel. Setting the system up was also a fairly complex task, and not something that could be done "on the fly". In the end they were used almost entirely for static emplacements, field units continuing to rely on their original iron sights or the simple Stiffkey-Stick sights that were introduced in late 1943.

The No.7 anti-aircraft composite predictor, also designed by Kerrison was similar in some ways. It was originally developed for the 6-pounder naval gun, for close-in defence and also against targets at intermediate altitudes of 6,000 to 14,000 ft (1,800 to 4,300 m). It was later adapted for use with the 40 mm Bofors.

Lab works-09(data files)

 Questions:

q1) Write a program to enter name,roll_no, and marks of 10 students and store them in the file.

q2)Write a program to store empid,name and salary of 10 employees in a datafile and print the records from the file.

q3)Write a program using C language that reads successive records from new data file and display each record on the screen in an appropriate format.

q4)Write a program to store std_id,name and marks of 'n' students in a data file.Display the records in appropriate format reading from the file.

q5)Write a program to enter name,roll_no and marks of 10 students and store them in the file.Read and display the record from the file.

-------------------------------------------------------------------------------------------------

solution:-

q1) Write a program to enter name,roll_no, and marks of 10 students and store them in the file.

ans:-

code:

//to store roll,name and percentage of some students
#include<stdio.h>       //header file
#include<conio.h>
int main()
{
FILE *k;                                                                    //  pointer for file declaration
char name[30];                                                    //identifier declaration
int roll,count=1;                                                              //       "             "
float per;
k=fopen("student.txt","w");//file opening
do
{

printf("enter record=%d",count);
printf("\nenter roll\n");   //data input
scanf("%d",&roll);

printf("enter  name\n");           // getting inputs

scanf("%s",name);
printf("enter percentage\n");
scanf("%f",&per);

fprintf(k,"%d %s %f\n",roll,name,per); //writing data to data file
printf("-------------------------------\n");//prints message
count++;                           
}while(count<=10);        //writing repeats as you enter 'y'                             
printf("\n writing process completed successfully\n");
fclose(k);                            //closing of file                       
getch();
return 0;
}

q2)Write a program to store empid,name and salary of 10 employees in a datafile and print the records from the file.

Ans:-

code:

//to store empid,name and salary of 10 employees
#include<stdio.h>       //header file
#include<conio.h>
int main()
{
FILE *k;                                                                    //  pointer for file declaration
char ename[30];                                                    //identifier declaration
int empid,count=1;                                                              //       "             "
float esalary;
k=fopen("emp.txt","w");//file opening
do
{

printf("enter record for=%d employee",count);
printf("\nenter empid\n");   //data input
scanf("%d",&empid);

printf("enter  ename\n");           // getting inputs
scanf("%s",ename);
printf("enter salary\n");
scanf("%f",&esalary);

fprintf(k,"%d %s %f\n",empid,ename,esalary); //writing data to data file
printf("-------------------------------\n");//prints message
count++;                           
}while(count<=10);        //writing repeats as you enter 'y'                             
printf("\n writing process completed successfully\n");
fclose(k);                            //closing of file    

k=fopen("emp.txt","r");//file opening

while((fscanf(k,"%d %s %f\n",empid,ename,esalary))!=EOF)   
//reading process goes on until the file ends(End of File)
{
printf("empid=%d name=%s salary=%f\n",empid,ename,esalary);   //printing on screen
}

printf("\n reading process completed successfully\n");                   
getch();
return 0;
}

q3)Write a program using C language that reads successive records from new data file and display each record on the screen in an appropriate format.
ans:
code:-
//to read empid,name and salary of  employees from data file
#include<stdio.h>       //header file
#include<conio.h>
int main()
{
FILE *k;                                                                    //  pointer for file declaration
char ename[30];                                                    //identifier declaration
int empid,count=1;                                                              //       "             "
float esalary;
k=fopen("emp.txt","r");//file opening
printf("read records are:\n");
while((fscanf(k,"%d %s %f\n",empid,ename,esalary))!=EOF)
//reading process goes on until the file ends(End of File)
{
printf("empid=%d name=%s salary=%f\n",empid,ename,esalary);   //printing on screen
}
printf("\n reading process completed successfully\n");
fclose(k);                                                           //closing data file
getch();
return 0;
}

q4)Write a program to store std_id,name and marks of 'n' students in a data file.Display the records in appropriate format reading from the file.

ans:-

code:-

//to store std_id,name and marks(5 subjects) of some students
#include<stdio.h>       //header file
#include<conio.h>
int main()
{
FILE *k;                                                                    //  pointer for file declaration
char sname[30],choice;                                                    //identifier declaration
int sid;                                                              //       "             "
int eng,acc,eco,bstd,csc;
k=fopen("sdetail.txt","w");//file opening
printf("we are going to write /store data\n");
do
{
printf("\nenter sid\n");   //data input
scanf("%d",&sid);

printf("enter  name\n");           // getting inputs
scanf("%s",sname);
printf("enter marks of english\n");
scanf("%d",&eng);

printf("enter marks of account\n");
scanf("%d",&acc);

printf("enter marks of eco.\n");
scanf("%d",&eco);

printf("enter marks of bstd\n");
scanf("%d",&bstd);

printf("enter marks of csc\n");
scanf("%d",&csc);

fprintf(k,"%d %s %d %d %d %d %d\n",sid,sname,eng,acc,eco,bstd,csc); //writing data to data file
printf("want to continue (y/n)\n");//prints message
choice=getche();                      //gets a character                                  //getting a character from user
}while(choice!='n');        //writing repeats as you enter 'y'                                    // validating the input
printf("\n writing process completed successfully\n");
fclose(k);                            //closing of file                                                            //closing data file
printf("-----------------------------------------------\n");
printf("read records are:\n");
k=fopen("sdetail.txt","r");//file opening

while((fscanf(k,"%d %s %d %d %d %d %d",&sid,sname,&eng,&acc,&eco,&bstd,&csc))!=EOF)
//inputs goes until the file ends(End of File)
{
printf("sid=%d sname=%s ,eng=%d acc=%d,eco=%d,bstd=%d,csc=%d\n",sid,sname,eng,acc,eco,bstd,csc);  //printing on screen
}
printf("\n reading process completed successfully\n");
fclose(k);                                                           //closing data file

getch();
return 0;
}

q5)Write a program to enter name,roll_no and marks of 10 students and store them in the file.Read and display the record from the file.

ans:-

code:

//to store std_id,name and marks(5 subjects) of 10 students
#include<stdio.h>       //header file
#include<conio.h>
int main()
{
FILE *k;                                                                    //  pointer for file declaration
char sname[30];                                                    //identifier declaration
int roll_no,count=1;                                                              //       "             "
int eng,acc,eco,bstd,csc;
k=fopen("sdetail.txt","w");//file opening
printf("we are going to write /store data\n");
do
{

printf("enter record for %d student\n",count);
printf("\nenter roll no.\n");   //data input
scanf("%d",&roll_no);

printf("enter  name\n");           // getting inputs
scanf("%s",sname);
printf("enter marks of english\n");
scanf("%d",&eng);

printf("enter marks of account\n");
scanf("%d",&acc);

printf("enter marks of eco.\n");
scanf("%d",&eco);

printf("enter marks of bstd\n");
scanf("%d",&bstd);

printf("enter marks of csc\n");
scanf("%d",&csc);

fprintf(k,"%d %s %d %d %d %d %d\n",roll_no,sname,eng,acc,eco,bstd,csc); //writing data to data file
count++;

printf("-----------------------------------\n");
}while(count<=10);      
printf("\n writing process completed successfully\n");
fclose(k);                            //closing of file                                                            //closing data file
printf("-----------------------------------------------\n");
printf("read records are:\n");
k=fopen("sdetail.txt","r");//file opening

while((fscanf(k,"%d %s %d %d %d %d %d",&roll_no,sname,&eng,&acc,&eco,&bstd,&csc))!=EOF)
//inputs goes until the file ends(End of File)
{
printf("roll no=%d sname=%s ,eng=%d acc=%d,eco=%d,bstd=%d,csc=%d\n",roll_no,sname,eng,acc,eco,bstd,csc);  //printing on screen
}
printf("\n reading process completed successfully\n");
fclose(k);                                                           //closing data file

getch();
return 0;
}


----------------------------------------------------------------------------------------------------------------------

case study:

Write a menu driven program which performs the following tasks.

1.Create a data file named "class12.data" and write record(roll_no,name,class and age) of student until 'n' is typed.

2.read all records from same file and display on the screen in appropriate format.

3.Display records of students whose age is more than 18.

4.Delete the particular record from the datafile on the basis of roll

5.Exit


Lab works-08(Pointer)

 Questions:-

q1)Write a program to swap two numbers using pointer.

q2)Write a program using call by value and call by reference to swap two numbers

3.)Write a progrm to input 25 numbers and display them in ascending order.

4.)Write a program to input 100 numbers and search a given number given by user.

5.)Write a program to calculate the sum and average of 10 numbers.

-----------------------------------------------------------------------------------------------

solution:

q1)Write a program to swap two numbers using pointer.

ans:-

code:

//pointer to swap two numbers
#include <stdio.h>

int main()
{
    int num1,num2,t;                //variables declaration
    int *p1,*p2;                     //pointer to store address
    printf("enter two numbers\n");
    scanf("%d%d",&num1,&num2);      //gets input
    printf("before swapping\n");
    printf("num1=%d,num2=%d\n",num1,num2);//display of values before swap
    p1=&num1;                             //assignment of address to first pointer
    p2=&num2;                              // assignment of address to second pointer
    t=*p1;                                //assigning first value to third variable
    *p1=*p2;                              //assigning second value to first pointer
    *p2=t;                                 //assigning first  value to second pointer
     printf("after swapping\n");
    printf("num1=%d,num2=%d\n",num1,num2);//prints values after swapping
    return 0;
}

q2)Write a program using call by value and call by reference to swap two numbers

ans:-

code:

call by value:

// call by value
#include <stdio.h>

void callbyvalue(int, int);                            /* function Prototype i.e. function declaration */

void main()                                                 /* Main function */
{
  int x = 10, y= 20;                                 // variables declaration

                                                                    /* actual arguments will be as it is */
  callbyalue(x, y);                             // passing value of x and y
  printf("x= %d, y= %d\n", x, y);    // displaying the values
}

void callbyvalue(int m, int n)             // passing values to formal parameter m and n
{
  int t;
  t = m;
m = n;
 n = t;                              // swapping takes place
}

call by reference:

// call by value reference
#include <stdio.h>
void callbyref(int*, int*);             /* function Prototype with two pointer as parameter*/

int main()                            /* Main function */
{
  int x = 10, y = 20;                 //variable declaration

    printf("before calling\n");                        
  printf("x=%d,y=%d\n",x,y);        //value display before call
  callbyref(&x, &y);              // passing address; /* actual arguments will be altered */
  printf("after calling\n");
  printf("x= %d, y= %d\n", x, y);   //displaying value after calling
  return 0;
}

void callbyref(int *m, int *n)
{
  int t;
  t = *m;
  *m = *n;
  *n = t;                       //swapping being done
}

3.)Write a program to input 25 numbers and display them in ascending order.

ans:-

code:

//program to sort numbers using pointer //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[25],i,j,k;          //variable declaration
    printf("enter  numbers\n");
    for(i=0;i<25;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("before sorting,values are\n");
    for(i=0;i<25;i++)
    {
        printf("%d\n",*(a+i));//displays its value with the help of address before sorting
    }
    printf("after sorting,values are\n");
    for(i=0;i<25;i++)
    {
        for(j=i+1;j<25;j++)
        {
            if(*(a+i)>*(a+j))               //sorting swapping taking place with its value
            {
                k=*(a+i);
                *(a+i)=*(a+j);
                *(a+j)=k;
            }
        }
    }
    for(i=0;i<25;i++)              //value display in sorted form
{
    printf("%d\n",*(a+i));
}
    return 0;
}

4.)Write a program to input 100 numbers and search a given number given by user.

ans:-

code:

//program to print all locations of a number  array. //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[100],i,k,num;          //variable declaration

int found=0;
    printf("enter numbers\n");
    
    p=a;                       //stores base address
    for(i=0;i<100;i++)      //runs from 0 to one less than 100
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<100;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
    printf("enter a number to be searched\n");
    scanf("%d",&num);                    //gets a number to be searched
    for(i=0;i<100;i++)
    {
            if(*(p+i)==num)               //comparison being done  with its value
            {
                 found=1;

                    break;

            }
    }

if(found==1)

{

printf("num=%d found and its location=%d\n",num,i);//prints value

}

else

{

printf("%d not found in the list.\n",num);

}
    return 0;
}

5.)Write a program to calculate the sum and average of 10 numbers.

Ans:

code:-

//program to print sum and average of 10 numbers using pointer. 
#include <stdio.h>           
int main()                  
{
    int *p;                   
    int a[20],i,k,sum=0;          //variable declaration
    
    printf("enter numbers\n");
    
    p=a;                       //stores base address
    for(i=0;i<10;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
        sum=sum+*(p+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
    return 0;
}

----------------------------------------------------------------------------------------------------------

case study:-

Discuss the similarity and differences between array and pointer.

ans:-

Similarity:-

With the help of following points, we can show some similarities between array and pointer.

1.array and pointer , both are variables.

2.For an array a[4], if we write a+0, it  is same as p+0 using pointer after assigning base address.

3.They both can store multiple data items.

Differences:

Array

Pointer

Array is a constant pointer.

Pointer variable can be changed.

It refers directly to the elements.

It refers address of the variable.

Memory allocation is in sequence.

Memory allocation is random.

Allocates the memory space which cannot resize or reassigned.

Allocated memory size can be resized.

It is a group of elements.

It is not a group of elements. It is a single variable.

Array can be initialized at definition. Example
int num[] = { 2, 4, 5}

Pointer can’t be initialized at a definition

The assembly code of Array is different than Pointer.

The assembly code of Pointer is different than Array.