Starting from:

$25

Prep and CLion_Lab 11 Solution

– Lab 11– PA3 Prep and CLion

Goals:

·         Use Eclipse to compile a program with multiple files

·         Provide an outline for CSCI 1410 PA3

Development Environment: all students must use Clion

Skills:Dynamic Arrays of Characters forming CStrings, definition of a namespace to allow use of a std::string versus an Example::string.

Reading: CSCI 1410 PA3 Prep/CSCI 1410 PA3

Deliverables:1) This lab withtwoscreen shots2) lastnameFirstLab10.cpp

 

Part I – Skills Practice (10 points)

·         Unlike Visual Studios which has its own built in C++ compiler as part of the program,.C-Lion is an application that is just a front-end editor and environment.  Clion is a professional Individual Development Environment with an annual license fee, but is free to students.  The company that makes CLion also makes a number of other IDEs for other languages.  It is important that you have used many different IDEs so when you apply to jobs, you can easily configure and use whichever IDE your company requires.  CLion requires an updated Java Run Time Environment and will run on Windows, Mac and many linux platforms. 

·         If loading on your own PC system, you would first load mingw, which is a minimum linux emulator.  It takes the g++ compiler and makes a Windows based executable out of it.

·         Then you would download JetbrainsCLion.  That will require you to set up an account using your .edu account.  You get one year free access, renewable each year as long as you are a student.

·         This has already been done on the Windows machines in the lab.

·         Go to the Window-Jetbrains-Clion

·         Go to File-New Project

·         Change the untitled name to Lab11a



·         You will get a screen like this:



·         Replace the main.cpp text with this

#include <iostream
#include <string

namespace Example
{
struct string

{
char * dynamicArray;
intsize =0;
    };
}

using namespace std;
intmain()
{
Example::string myString;
/*Use the Example:: to differentiate.  By saying using namespace std we say if we don't specify assume the std string.  If we want to specify, we use the name of the namespace with a ::*/
string string1, string2;
cout<<"Type a string that you want converted to a C String:\n";
getline (cin, string1);
myString.size= string1.size()+ 1;

//String class size does not count the '/n'
myString.dynamicArray= new char[(myString.size)];
for (inti=0; i<string1.size(); i++)
    {
myString.dynamicArray[i] = string1[i];
    }
myString.dynamicArray[myString.size-1] = '\0'; //Backslash Zero
cout<<"The string input was:\n" <<string1<<endl;
    string2 = string(myString.dynamicArray);
cout<<"The string, converted to a dynamic array, then coverted back to a string is \n";
cout<<string2 <<endl;
return 0;
}

 

 

·         Now if you did everything correctly it should compile. If it has errors, try to fix the errors by reading the error and clicking on the link to the error.

·         Once it successfully compiles, go to Run-Run Lab 11a

·         Take a screenshot of the successful output below:



 

Part II- outline/pseudo-code/algorithms (5 pts)

Using the debugger is a key skill that you will use often, especially when dealing with pointers.  Every time you use a new Individual Development Environment (IDE), you should learn how to use the debugger, and what kind of information this debugger will give you.

 

·         In the main.cpp, click just to the right of the number  on the line

myString.dynamicArray[i] = string1[i];

·         and you will get a red circle



·         Now Run-Build

·         Run Debug Lab 11a

·         You should get a black screen asking you to type a String.  Type in your first and last name.  Once you type that string you should get some information in the main.cpp and windows below, under Debugger tab



·         Hit the arrow on myString to expand it.  Click on the blue down arrow (Step Over) as many times as there are characters.  Note that the for loop is changing the value of myString.

Ø  When you have copied your entire name to myString (including the last ‘\0’ string delimiter) make a screen shot of the Debugger frame and place it below:



Part III- outline/pseudo-code/algorithms (15 pts)

·         Work alone to write the pseudo-code and outline for CSCI 1410 Programming Assignment 3. Note that we haven’t yet gone over vectors or much with classes (other than what you typed above), but you can put in plain English what you are expecting to do.  If you use any major concepts from someone other than your instructor, you must list it in the comments.  You may create this outline in any IDE.

/* Name:
Class: CSCI 1411-00X
Description: [fill in description]

Lab Partner:
Status: successfully compiled and run on csegrid [Since this is an outline, it is not expected to compile, but the status should say so!/*

 

·         If you put a full effort on this lab, you will be completing a requirement that will also be graded in CSCI 1410.  Upload only the .cpp and .h files to Canvas.

More products