Skip to content

[FOSS] Task-03: Complete Calculator Feature Using Stash & Cherry-Pick (First Year Only)Β #103

@23abdul23

Description

@23abdul23

FOSS β€” Third Issue πŸš€

Git Commit Stash and Cherry Pick

Issue Type

FOSS · Intermediate · Open for All 🌍

Contribution Rules βœ…

  • Work only on foss and foss-task-03 branch
  • Original content only (No AI usage, otherwise Straight PR Rejection)

Objective

Learn how to use git stash and git cherry-pick to safely complete a real calculation feature when work is blocked by upstream changes.

Scenario

A calculator function is split into two parts:

  • Part A – Validation + GST calculation
  • Part B – Discount logic

Part B already exists in another branch (foss-task-03).
You must safely combine both parts into the working foss branch.

Setup

Branch foss-task-03 contains calculator.cpp with the required implemented part of the function:

#include <iostream>
using namespace std;

/*
  Function: calculateFinalAmount
  Purpose : Calculates final payable amount after tax and discount.
*/

double calculateFinalAmount(double amount, int customerType) {
    //Part A


    //Part B
}

int main() {
    double amount;
    int type;

    cout << "Enter bill amount: ";
    cin >> amount;

    cout << "Enter customer type (1-Regular, 2-Premium): ";
    cin >> type;

    double payable = calculateFinalAmount(amount, type);
    cout << "Final Payable Amount: " << payable << endl;

    return 0;
}

Implement Part A as follow:

Check if amount is valid, if less than or equal to 0, print "Invalid Amount" and return.
Otherwise make two variables tax and total. tax will be 18% of the amount and total will be summation of tax and amount.

Steps

  1. Checkout the foss branch.
  2. Copy the above code inside the file calculator.cpp placed inside task-03/. Implement Part A only, by your own (do not commit)
  3. Stash changes using git stash push -m "calculator-part-a"
  4. Check out the foss-task-03 branch. (You may need to fetch it by running git switch -c foss-task-03 origin/foss-task-03)
  5. Cherry-pick Part B commit from foss-task-03, the lastest commit on this branch.
  6. Pop stash and resolve conflicts if any.
  7. Make a folder of your own <githubId>/ inside the task-03/ folder, place your calculator.cpp file inside there.
  8. Commit final calculator function.

Mandatory PR Requirement

git log --oneline --graph --all
git stash list

Attach screenshots.

PR Submission

  • Part A and Part B both exist
  • Cherry-pick and stash used correctly
  • Screenshots attached
  • Answer the hidden question asked during the task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Points: 30open-for-allAny one can work on it without getting assigned, every PR can merge

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions