A new method to construct $q$-ary complementary sequence (or array) sets (CSSs) and complete complementary codes (CCCs) of size $N$ is introduced in this paper. An algorithm on how to compute the explicit form of the functions in constructed CSS and CCC is also given. A general form of these functions only depends on a basis of functions from $Z_N$ to $Z_q$ and representatives in the equivalent class of Butson-type Hadamard matrices. Surprisingly, all the functions fill up a larger number of cosets of a linear code, compared with the existing constructions. From our general construction, its realization of $q$-ary Golay pairs exactly coincides with the standard Golay sequences. The realization of ternary complementary sequences of size $3$ is first reported here. For binary and quaternary complementary sequences of size 4, a general Boolean function form of these sequences is obtained. Most of these sequences are also new. Moreover, most of quaternary sequences cannot be generalized from binary sequences, which is different from known constructions. More importantly, both binary and quaternary sequences of size 4 constitute a large number of cosets of the linear code respectively.