Java/C/C++ Programming in Linux 


Program Objective:


1. This program is intended to get you acquainted with Linux (or refresh your programming experience).  This will be a short interactive program that will get you started an editor in Linux (pico, vi, emacs, etc.).


2. It will get you through compiling, linking, and running a program.  You may write the program in Java, C, or C++ - your choice. 


Editing: Program in Linux, use the editors in the Linux environment . There are a number of ways this can be done. The easiest way is to use the pico editor.  Also available are vi and emacs editors.


Compiling: The compiler is gcc  (or g++ or javac). This can be used from the command prompt. Sample compilation is


For C program: gcc –o test test.c                   (source program is test.c)

For C++ program: g++ -o test test.cpp          (source program is test.cpp)

For Java program: javac test.java                 (source program is test.java. This command generates test.class)



Executing: Here, test is the executable file name, and the execution is as follows.

For C or C++ program: . /test

For Java program: java test


Program Description:


Write a small Linux program that will calculate the temperature in degrees F, given the temperature in degrees C, where C is 34.5. (The formula is.. F = (9/5) * C + 32.0). 


You must perform the calculation as a separate function such as convert(C). The caller invokes the function as in convert(34.5)


Your program should print out the corresponding Fahrenheit degrees, and then terminate.


Program requirements:


Enough documentation (either embedded in the code with comments, or external) to explain how you parsed the program and to follow what you expect to happen.

Source code for your program (file name linuxfc.c or linuxfc.cpp or linuxfc.java )

Submit your source code to Week 4 dropbox.


// Every thing is commented for proper understanding

// The function is also made as needed


#include <iostream

using namespace std;


void programOverview ();

char getScale ();

int getDegree ();

float convertFtoC (float);

float convertCtoF (float);

int getResults ();


int main ()


  cout.precision (2);

  programOverview ();

  getDegree ();



  if (scale == "F")




  else if (scale == "C")





    cout << "ERROR: Invalid temperature scale" << endl;




  return 0;



//This function displays a brief overview explaining the program to the user

void programOverview ()


  cout << "This program will convert a temperature reading provided in" << endl;

  cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;



//This function requires the user to enter the temperature scale to be used

char getScale ()


  char scale;

  cout << "Enter the letter of the temperature scale that will be used:" << endl;

  cout << "F = Fahrenheit; C = Celsius)" << endl;

  cin scale endl;

  return scale;



//This function requires the user to enter the temperature reading in degrees

int getDegree ()


  int degree;

  cout << "Enter your temperature reading in degrees:" << endl;

  cin degree;

  return degree;



//This function converts a Fahrenheit temperature to Celsius

float convertFtoC (float Ftemp)


  float Ctemp;

  Ctemp = (Ftemp - 32) / 1.8;

  return Ctemp;



//This function converts a Celsius temperature to Fahrenheit

float convertCtoF (float Ctemp)


  float Ftemp;

  Ftemp = 1.8 * Ctemp + 32;

  return Ftemp;



//This function displays the results


  int getResults ()

  cout << "Your temperature reading converts as follows:" << endl;

  cout << "Fahrenheit:" << return Ftemp << endl;

  cout << "Celsius:" << return Ctemp << endl;

Powered by