Student project in 2026
During the semester the students will (individually) work on a larger project. They will step by step create a Polynom class and its test environment. For every time you have to create a small additional task built on the previous results. We publish the solutions of every steps after some delay, so if you are disrupted for a while you still can catch up later.
Please, do not use AI to genereate code, but you can use it to generate test cases.
Submit the solutions on Canvas just copy-paste-ing the source code including the main() function and the code you wrote.
Task 1: Create a pretty printer for polynoms
Write a pretty printer function for polynoms which returns a string representation of the polynom. The polynom is given by its coefficients, stored in a std::vector (the lower coefficients are in the lower indexes).
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <vector>
std::string to_string(std::vector<int> v);
int main()
{
std::vector<int> v = { -2, 0, 5, -3, 8};
std::string s = to_string(v);
std::cout << s << '\n';
return 0;
}
Expected result is:
8X^4-3X^3+5X^2-2Consider the edge cases: 0 degree polynom, no constant tag, negatives, etc.. Write a main() function which tests your function with various cases. Use the std::to_string() function to convert numbers to string.
Submit your solution to Canvas by 15th March, 23:59h.
Remark: For empty vector just return empty string: “”. For one element vector return just the constant, e.g.: “5”. For linear function tag return X instead of X^1.