FYBCS C Exercise_1

Set A . Apply all the three program development steps for the following examples. 

 1. Accept dimensions of a cylinder and print the surface area and volume (Hint: surface area =2πr2 + 2πrh, volume = πr2h)

 2. Accept temperatures in Fahrenheit (F) and print it in Celsius(C) and Kelvin (K) (Hint: C=5/9(F-32), K = C + 273.15)

 3. Accept initial velocity (u), acceleration (a) and time (t). Print the final velocity (v) and the distance (s) travelled. (Hint: v = u + at, s = u + at2)

 4. Accept inner and outer radius of a ring and print the perimeter and area of the ring (Hint:perimeter = 2 π (a+b) , area = π (a2-b2) )

 5. Accept two numbers and print arithmetic and harmonic mean of the two numbers (Hint: AM=(a+b)/2 , HM = ab/(a+b) )

 6. Accept three dimensions length (l), breadth(b) and height(h) of a cuboid and print surface area and volume (Hint : surface area=2(lb+lh+bh ), volume = lbh )

 7. Accept a character from the keyboard and display its previous and next character in order.Ex. If the character entered is ‘d’, display “The previous character is c”, “The next character is e”.

 8. Accept a character from the user and display its ASCII value.

Set B . Apply all the three program development steps for the following examples.

 1. Accept the x and y coordinates of two points and compute the distance between the two points.

 2. Accept two integers from the user and interchange them. Display the interchanged numbers.

 3. A cashier has currency notes of denomination 1, 5 and 10. Accept the amount to be withdrawn from the user and print the total number of currency notes of each denomination thecashier will have to give.

Set C. Write a program to solve the following problems

 1. Consider a room having one door and two windows both of the same size. Accept dimensions of the room, door and window. Print the area to be painted (interior walls) and area to be whitewashed (roof).

 2. The basic salary of an employee is decided at the time of employment, which may be different for different employees. Apart from basic, employee gets 10% of basic as house rent,30% of basic as dearness allowance. A professional tax of 5% of basic is deducted from salary.Accept the employee id and basic salary for an employee and output the take home salary of the employee. 

Post a Comment

11 Comments

  1. redhatt
    https://youtu.be/-iQnt159PDk?si=qxGQlOY0jL7662uM

    ReplyDelete
  2. SCAN.

    #include
    #include
    void scan(int req[],int n,int head,int size,int dir)
    {
    int seek=0,i,j,temp,bound=size,start;
    for(i=0;ireq[j])
    {
    temp=req[i];
    req[i]=req[j];
    req[j]=temp;
    }
    }
    }
    for(start=0;start=head)
    {
    break;
    }
    printf("seek sequence:%d",head);
    if(dir==1)
    {
    for(i=start;i%d",head);
    }
    seek+= abs(bound - head);
    head = bound;
    printf(" ->%d",head);
    for(i=start-1;i>=0;i--)
    {
    seek+=abs(req[i]-head);
    head=req[i];
    printf("->%d",head);
    }
    }
    else
    {
    for(i=start-1;i>=0;i--)
    {
    seek+=abs(req[i]-head);
    head=req[i];
    printf("->%d",head);
    }
    seek+= abs( head -0);
    head = 0;
    printf(" ->%d",head);
    for(i=start;i%d",head);
    }
    }
    printf("\n Total seek time:%d\n",seek);
    }
    int main()
    {
    int n,head,size,dir,i;
    printf("Enter number of requets:");
    scanf("%d",&n);
    int req[n];
    printf("Enter request queue:");
    for(i=0;i<n;i++)
    scanf("%d",&req[i]);
    printf("Enter disk size:");
    scanf("%d",&size);
    printf("Enter initial head position:");
    scanf("%d",&head);
    printf("Enter direction (1 for right,0 for left):");
    scanf("%d",&dir);
    scan(req,n,head,size,dir);
    return 0;
    }

    ReplyDelete
  3. C-SCAN Program :
    #include
    #include
    void cscan(int req[], int n, int head, int size, int dir)
    {
    int seek = 0, i, j, temp, bound = size,start;
    for (i = 0; i < n ; i++)
    {
    for (j = i + 1; j < n; j++)
    {
    if (req[i] > req[j])
    {
    temp = req[i];
    req[i] = req[j];
    req[j] = temp;
    }
    }
    }
    for (start = 0; start < n; start++)
    {
    if (req[start] >= head)
    {
    break;
    }
    }
    printf("Seek sequence: %d", head);
    if (dir == 1)
    {
    for (i = start; i < n; i++)
    {
    seek += abs(req[i] - head);
    head = req[i];
    printf(" -> %d", head);
    }
    seek += abs(bound - head);
    head = bound;
    printf(" -> %d", head);
    seek += abs(bound - 0);
    head = 0;
    printf(" -> %d", head);
    for (i = 0; i < start; i++)
    {
    seek += abs(req[i] - head);
    head = req[i];
    printf(" -> %d", head);
    }
    }
    else
    {
    for (i = start - 1; i >= 0; i--)
    {
    seek += abs(req[i] - head);
    head = req[i];
    printf(" -> %d", head);
    }
    seek += abs(head - 0);
    head = 0;
    printf(" -> %d", head);
    seek += abs(bound - 0);
    head = bound;
    printf(" -> %d", head);
    for (i = n - 1; i >= start; i--)
    {
    seek += abs(req[i] - head);
    head = req[i];
    printf(" -> %d", head);
    }
    }
    printf("\nTotal seek time: %d\n", seek);
    }
    int main()
    {
    int n, head, size, dir, i;
    printf("Enter number of requests: ");
    scanf("%d", &n);
    int req[n];
    printf("Enter request queue: ");
    for (i = 0; i < n; i++)
    scanf("%d", &req[i]);
    printf("Enter disk size: ");
    scanf("%d", &size);
    printf("Enter initial head position: ");
    scanf("%d", &head);
    printf("Enter direction (1 for right, 0 for left): ");
    scanf("%d", &dir);
    cscan(req, n, head, size, dir);
    return 0;
    }

    ReplyDelete
  4. import pandas as pd
    students = pd.DataFrame({'Name': ['om1', 'om2', 'om3', 'om4', 'om5'],'Graduation Percentage': [85, 90, 75, 95, 80],'Age': [22, 21, 23, 20, 24]})
    print("Average age of students:", students['Age'].mean())
    print("Average of graduation percentage:", students['Graduation Percentage'].mean())
    print(students.describe())

    ReplyDelete
  5. import pandas as pd
    i= pd.read_csv("D:\WT & FDS I\Revised Data Science_Workbook_ Assignment Solution\Data Science Assignment Solution\Iris.csv")
    sample = i.sample(100)
    print(sample.describe())

    ReplyDelete
  6. import pandas as pd
    iris = pd.read_csv('D:\WT & FDS I\Revised Data Science_Workbook_ Assignment Solution\Data Science Assignment Solution\Iris.csv')
    count = iris['Species'].value_counts()
    print(count)

    ReplyDelete
  7. from mlxtend.preprocessing import TransactionEncoder
    from mlxtend.frequent_patterns import apriori, association_rules
    import pandas as pd

    # Create the dataset
    data = [
    ['Bread', 'Milk'],
    ['Bread', 'Diaper', 'Beer', 'Eggs'],
    ['Milk', 'Diaper', 'Beer', 'Cake'],
    ['Bread', 'Milk', 'Diaper', 'Beer'],
    ['Bread', 'Milk', 'Diaper', 'Coke']
    ]

    # Convert categorical values into numeric format
    te = TransactionEncoder()
    te_ary = te.fit_transform(data)
    df = pd.DataFrame(te_ary, columns=te.columns_)

    # Apply Apriori algorithm with min_sup=2 (at least 2 transactions)
    frequent_itemsets = apriori(df, min_support=2/len(df), use_colnames=True)
    rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.7)

    support_values = rules['support']
    confidence_values = rules['confidence']


    # Print frequent itemsets and association rules
    print("Frequent Itemsets:")
    print(frequent_itemsets)
    print("\nconfidence Rules:")
    print(support_values)

    ReplyDelete
  8. // C++ Program to illustrate how to use a stack to convert
    // an infix expression to a postfix expression
    #include
    #include
    #include
    using namespace std;

    // Function to check the precedence of operators
    int precedence(char op)
    {
    if (op == '+' || op == '-')
    return 1;
    if (op == '*' || op == '/')
    return 2;
    return 0;
    }

    // Function to convert infix expression to postfix
    // expression
    string infixToPostfix(string infix)
    {
    stack st;
    string postfix = "";
    for (int i = 0; i < infix.length(); i++) {
    char c = infix[i];

    // If the scanned character is an operand, add it to
    // output string.
    if (isalnum(c))
    postfix += c;

    // If the scanned character is an '(', push it to
    // the stack.
    else if (c == '(')
    st.push('(');

    // If the scanned character is an ')', pop and to
    // output string from the stack until an '(' is
    // encountered.
    else if (c == ')') {
    while (st.top() != '(') {
    postfix += st.top();
    st.pop();
    }
    st.pop();
    }

    // If an operator is scanned
    else {
    while (!st.empty()
    && precedence(c)
    <= precedence(st.top())) {
    postfix += st.top();
    st.pop();
    }
    st.push(c);
    }
    }

    // Pop all the remaining elements from the stack
    while (!st.empty()) {
    postfix += st.top();
    st.pop();
    }

    return postfix;
    }

    int main()
    {
    string infix = "A+B*C";
    cout << "Infix Expression: " << infix << endl;
    cout << "Postfix Expression: " << infixToPostfix(infix)
    << endl;
    return 0;
    }

    ReplyDelete
  9. def is_prime(n):
    if n <= 1:
    return False
    i = 2
    while i * i <= n:
    if n % i == 0:
    return False
    i += 1
    return True

    def check_number(num_list):
    for num in num_list:
    if is_prime(num):
    print(f"{num} is prime")
    if num % 2 == 0:
    print(f"{num} is even")
    else:
    print(f"{num} is odd")

    num_list = [2, 3, 4, 5, 6, 7, 8, 9, 10]
    check_number(num_list)

    ReplyDelete
  10. #include
    #include
    #define MAX_SIZE 5

    class CircularQueue {
    int arr[MAX_SIZE];
    int front, rear;
    public:
    CircularQueue() {
    front = -1;
    rear = -1;
    }

    int isFull() {
    return (front == (rear + 1) % MAX_SIZE);
    }

    int isEmpty() {
    return (front == -1);
    }

    void enqueue(int value) {
    if (isFull()) {
    cout << "Queue Overflow!" << endl;
    return;
    }
    if (isEmpty()) {
    front = 0;
    rear = 0;
    } else {
    rear = (rear + 1) % MAX_SIZE;
    }
    arr[rear] = value;
    cout << value << " enqueued to the queue." << endl;
    }

    void dequeue() {
    if (isEmpty()) {
    cout << "Queue Underflow!" << endl;
    return;
    }
    cout << arr[front] << " dequeued from the queue." << endl;
    if (front == rear) {
    front = -1;
    rear = -1;
    } else {
    front = (front + 1) % MAX_SIZE;
    }
    }

    void display() {
    if (isEmpty()) {
    cout << "Queue is empty!" << endl;
    return;
    }
    cout << "Queue elements: ";
    int i = front;
    while (1) {
    cout << arr[i] << " ";
    if (i == rear)
    break;
    i = (i + 1) % MAX_SIZE;
    }
    cout << endl;
    }
    };

    void main() {
    clrscr();
    CircularQueue queue;
    int choice, value;
    cout << "Circular Queue Operations Menu:\n";
    cout << "1. Enqueue\n2. Dequeue\n3. Display\n4. Exit\n";
    while (1) {
    cout << "\nEnter your choice: ";
    cin >> choice;
    switch (choice) {
    case 1:
    cout << "Enter value to enqueue: ";
    cin >> value;
    queue.enqueue(value);
    break;
    case 2:
    queue.dequeue();
    break;
    case 3:
    queue.display();
    break;
    case 4:
    cout << "Exiting program..." << endl;
    getch();
    exit(0);
    default:
    cout << "Invalid choice! Try again." << endl;
    }
    }
    getch();
    }

    ReplyDelete