Menu
CoddyTech

Recap: Parcel Charges

Lesson 6 of 48 in Coddy's C++ for Python Developers course.

challenge icon

Challenge

Easy

Input: item count and unit price. Cost is their product plus 5 shipping if the product is below 30; no shipping for zero items.

Implement the declared API in exercise.hpp and exercise.cpp. Both files are editable; preserve the public signatures. The locked main.cpp reads stdin and calls the API directly. It also checks public API behavior independently where stated. Return values rather than printing inside the API. Integer inputs and results fit signed int; text is ASCII unless stated otherwise.

Try it yourself

#include "exercise.hpp"
#include <iostream>
int main(){

std::vector<std::string> rows; std::string line; while(std::getline(std::cin,line)) rows.push_back(line);
std::istringstream in(rows.empty()?"":rows[0]);int n,p;in>>n>>p;std::cout<<charge(n,p)<<"\n";
}

All lessons in C++ for Python Developers

Practice on your own: Online C++ compiler