Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a header file and a .cc file containing the implementation of the overloaded C++ functions: void cmpe180ASort(int a[], int sz); void cmpe180ASort(char c[], int

Create a header file and a .cc file containing the implementation of the overloaded C++ functions:

void cmpe180ASort(int a[], int sz);

void cmpe180ASort(char c[], int sz);

This is the question and for this i have created a header file with the functions

void cmpe180ASort(int a[], int sz);

void cmpe180ASort(char c[], int sz);

in it and i have created a .cc file with the functions implementation and i have created a test file that contains main function.

Now when am trying to link both the cc file and the test file, i am getting the below error

usr/bin/ld: Hw1.o: warning: relocation against `_ZSt4cout' in read-only section `.text' /usr/bin/ld: Hw1.o: in function `cmpe180ASort(int*, int)': Hw1.cc:(.text+0xf0): undefined reference to `std::cout' /usr/bin/ld: Hw1.cc:(.text+0xf5): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)' /usr/bin/ld: Hw1.cc:(.text+0xff): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)' /usr/bin/ld: Hw1.cc:(.text+0x10a): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /usr/bin/ld: Hw1.cc:(.text+0x138): undefined reference to `std::cout' /usr/bin/ld: Hw1.cc:(.text+0x13d): undefined reference to `std::ostream::operator<<(int)' /usr/bin/ld: Hw1.cc:(.text+0x144): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)' /usr/bin/ld: Hw1.cc:(.text+0x14e): undefined reference to `std::cout' /usr/bin/ld: Hw1.cc:(.text+0x153): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /usr/bin/ld: Hw1.o: in function `cmpe180ASort(char*, int)': Hw1.cc:(.text+0x225): undefined reference to `std::cout' /usr/bin/ld: Hw1.cc:(.text+0x22a): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)' /usr/bin/ld: Hw1.cc:(.text+0x234): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)' /usr/bin/ld: Hw1.cc:(.text+0x23f): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /usr/bin/ld: Hw1.cc:(.text+0x26a): undefined reference to `std::cout' /usr/bin/ld: Hw1.cc:(.text+0x26f): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char)' /usr/bin/ld: Hw1.cc:(.text+0x276): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)' /usr/bin/ld: Hw1.cc:(.text+0x280): undefined reference to `std::cout' /usr/bin/ld: Hw1.cc:(.text+0x285): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /usr/bin/ld: Hw1.o: in function `__static_initialization_and_destruction_0(int, int)': Hw1.cc:(.text+0x2bb): undefined reference to `std::ios_base::Init::Init()' /usr/bin/ld: Hw1.cc:(.text+0x2d0): undefined reference to `std::ios_base::Init::~Init()' /usr/bin/ld: warning: creating DT_TEXTREL in a PIE collect2: error: ld returned 1 exit status

To be precise, i am trying to do all this in terminal in ubuntu using g++ commands and the code is as follows:

HeaderFIle:

void cmpe180ASort(int a[],int sz); void cmpe180ASort(char c[],int sz);

Implementation.cc

#include using namespace std; void cmpe180ASort(int a[],int sz) { int i,j,t; for(i=sz-1;i>=0;i--){ for(j=0;j if(a[j]>a[j+1]){ t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } cout<< "The elements of the sorted integer array are:"< for(int i=0;i cout< cout< } } void cmpe180ASort(char c[],int sz) { int i,j,t; for(i=sz-1;i>=0;i--){ for(j=0;j< i;j++){ if(c[j]>c[j+1]){ t=c[j]; c[j]=c[j+1]; c[j+1]=t; } }

I have seen in the comments that the code is not correct. Can you suggest the faults in it? } cout<< "The elements of the sorted Character array are:"< for(int i=0;i cout< cout< } }

Main.cc

#include #include"Hw1.h" #include using namespace std; int main(){ int b[]={1,7,2,9,11}; cmpe180ASort(b,4); char d[]={'c','a','z','m','e','l'}; cmpe180ASort(d,5); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

4. What sales experience have you had?

Answered: 1 week ago

Question

15-5 How will MIS help my career?

Answered: 1 week ago