Question

#include <iostream> #include <string> using namespace std; string STUDENT = "ckim84"; // Add your Blackboard login...

#include <iostream>
#include <string>
using namespace std;

string STUDENT = "ckim84"; // Add your Blackboard login name
extern string ASSIGNMENT;


/**
* Describe the purpose of your program here.
* @return 0 for success.
*/
int run()
{

repeatChar(3, "abcde$");
return 0;
}

string repeatChar(int n, const string& pat)
{
string result;
for (int i = 0; i < n; i++)
{
result += pat;
}
return result;
}

could you correct my code?? i got an error msg like below :

h02.cpp:22:1: error: use of undeclared identifier 'repeatChar'
repeatChar(3, "abcde$");
^
1 error generated.
make: *** [h02.o] Error 1

i tried to write a code to input some random values in the fuction. I think this way I did works on java, but for some reason, it doesnt work at all on c++.

Homework Answers

Answer #1

Program:

#include <iostream>
#include <string>
using namespace std;
string STUDENT = "ckim84"; // Add your Blackboard login name
extern string ASSIGNMENT;

/**
* Describe the purpose of your program here.
* @return 0 for success.
*/
/* int run()
{
return 0;
} */ // Here no need to write run method


string repeatChar(int n, const string& pat)
{
string result;
for (int i = 0; i < n; i++)
{
result += pat;
}
return result;
}
int main() {
repeatChar(3, "abcde$");
   return 0;
}

Output: Executed successfully

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {...
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {    hacked[0] = hacked[1] = hacked[2] = false;    passwords[agent_index(MrMean)] = random_pw(MrMean);    passwords[agent_index(MsChief)] = random_pw(MsChief);    passwords[agent_index(DrEvil)] = random_pw(DrEvil); } void EvilServer :: change_pw(EvilAgent agent, string new_pw) {    int index = agent_index(agent);    if (new_pw == passwords[index])        return;    hacked[index] = false;    passwords[index] = new_pw; } string EvilServer :: random_pw(EvilAgent agent) {    string password;    int length;   ...
I have an error but i can't correct it #include <iostream> using namespace       std; long reverse...
I have an error but i can't correct it #include <iostream> using namespace       std; long reverse (long       num, long   equation,long reverse = 0); int       main() {               long       num, reverse = 0;        cout << "Enter       the       num:       ";        cin >> num;        cout << "Reverse       num       is       =       "               << reverse << endl;        return       0; } long reverse(long       num, long equation, long reverse = 0) {        while (num)        {               equation...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;   ...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;    int* myScore;    int myVar;       myInt = 10;    myScore = &myInt;    myVar = 20;    myVar = *myScore;    *myScore = 30;    myVar = 40;    myVar = *myScore;    } Group of answer choices 30 20 10 0
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
complete the following tasks in C++ code: #include <iostream> using namespace std; class Cube{ public: Cube(int,...
complete the following tasks in C++ code: #include <iostream> using namespace std; class Cube{ public: Cube(int, int,int); int getVolume(); private: int height; int weight; int depth; }; Cube::Cube(int h, int w, int l) { height = h; weight = w; depth = l; } int main(){ }